99import org .junit .jupiter .api .Test ;
1010import org .junit .jupiter .api .extension .ExtendWith ;
1111import org .junit .jupiter .params .ParameterizedTest ;
12- import org .junit .jupiter .params .provider .NullSource ;
13- import org .junit .jupiter .params .provider .ValueSource ;
12+ import org .junit .jupiter .params .provider .Arguments ;
13+ import org .junit .jupiter .params .provider .MethodSource ;
1414import org .mockito .*;
1515import org .springframework .data .domain .Page ;
1616import org .mockito .junit .jupiter .MockitoExtension ;
2020
2121import java .util .Arrays ;
2222import java .util .Optional ;
23-
24- import static org .mockito .ArgumentMatchers .any ;
23+ import java .util .stream .Stream ;
2524
2625@ ExtendWith (MockitoExtension .class )
2726class QuestionServiceTest {
@@ -60,9 +59,8 @@ void testFindAll() {
6059 }
6160
6261 @ ParameterizedTest
63- @ NullSource
64- @ ValueSource (strings = {"" , "Some Description" })
65- void testCreateWithDescriptionVariations (String description ) {
62+ @ MethodSource ("provideDescriptions" )
63+ void testCreateWithDescriptionVariations (String description , String expectedBody ) {
6664 QuestionRequestDTO request = new QuestionRequestDTO ();
6765 request .setTitle ("Title" );
6866 request .setDescription (description );
@@ -84,6 +82,8 @@ void testCreateWithDescriptionVariations(String description) {
8482 Assertions .assertEquals (request .getTitle (), capturedQuestion .getTitle ());
8583 Assertions .assertEquals (request .getDescription (), capturedQuestion .getDescription ());
8684 Assertions .assertEquals (1L , result .getId ());
85+
86+ Assertions .assertEquals (expectedBody , result .getBody ());
8787 }
8888
8989 @ Test
@@ -158,4 +158,12 @@ void deleteNonexistentQuestion() {
158158
159159 Mockito .verifyNoMoreInteractions (questionRepository );
160160 }
161+
162+ private static Stream <Arguments > provideDescriptions () {
163+ return Stream .of (
164+ Arguments .of (null , "Title\n null" ),
165+ Arguments .of ("" , "Title\n " ),
166+ Arguments .of ("Some description" , "Title\n Some description" )
167+ );
168+ }
161169}
0 commit comments