File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
src/test/java/com/example/postgresdemo/service Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 88import org .junit .jupiter .api .Assertions ;
99import org .junit .jupiter .api .Test ;
1010import org .junit .jupiter .api .extension .ExtendWith ;
11+ import org .junit .jupiter .params .ParameterizedTest ;
12+ import org .junit .jupiter .params .provider .NullSource ;
13+ import org .junit .jupiter .params .provider .ValueSource ;
1114import org .mockito .*;
1215import org .springframework .data .domain .Page ;
1316import org .mockito .junit .jupiter .MockitoExtension ;
@@ -56,15 +59,20 @@ void testFindAll() {
5659 Assertions .assertEquals ("Title2\n Description2" , result .getContent ().get (1 ).getBody ());
5760 }
5861
59- @ Test
60- void testCreate () {
62+ @ ParameterizedTest
63+ @ NullSource
64+ @ ValueSource (strings = {"" , "Some Description" })
65+ void testCreateWithDescriptionVariations (String description ) {
6166 QuestionRequestDTO request = new QuestionRequestDTO ();
6267 request .setTitle ("Title" );
63- request .setDescription ("Description" );
68+ request .setDescription (description );
69+
6470 Question question = new Question ();
6571 question .setId (1L );
6672 question .setTitle ("Title" );
67- question .setDescription ("Description" );
73+ question .setDescription (description );
74+
75+ ArgumentCaptor <Question > questionCaptor = ArgumentCaptor .forClass (Question .class );
6876 Mockito .when (questionRepository .save (questionCaptor .capture ())).thenReturn (question );
6977
7078 QuestionResponseDTO result = questionService .create (request );
You can’t perform that action at this time.
0 commit comments