1919import java .util .UUID ;
2020
2121import static org .hamcrest .MatcherAssert .assertThat ;
22- import static org .hamcrest .Matchers .is ;
23- import static org .hamcrest .Matchers .nullValue ;
22+ import static org .hamcrest .Matchers .*;
2423
2524public class ResponseTest {
2625 private static final String TEST_RESPONSE_URI = "/api/v1" ;
@@ -58,7 +57,7 @@ public void shouldReturnResponseWithDataAs1ObjectWithoutErrorsAndUriSpecified()
5857 assertThat (response .getMeta ().getPage ().getMaxSize (), is (25 ));
5958 assertThat (response .getMeta ().getPage ().getTotal (), is (1L ));
6059
61- assertThatAttributesIdFieldIsAbsentInObject (response );
60+ assertThatAttributesIdFieldIsPresentInObject (response );
6261 }
6362
6463 @ Test
@@ -92,7 +91,7 @@ public void shouldReturnResponseWithDataListWithoutErrorsAndUriSpecified() {
9291 assertThat (response .getMeta ().getPage ().getMaxSize (), is (25 ));
9392 assertThat (response .getMeta ().getPage ().getTotal (), is (2L ));
9493
95- assertThatAttributesIdFieldIsAbsentInCollection (response );
94+ assertThatAttributesIdFieldIsPresentInCollection (response );
9695 }
9796
9897 @ Test
@@ -116,7 +115,7 @@ public void shouldReturnResponseWithDataAndUriSpecifiedWithoutUriPlaceholdersAnd
116115 assertThat (response .getMeta ().getPage ().getMaxSize (), is (25 ));
117116 assertThat (response .getMeta ().getPage ().getTotal (), is (1L ));
118117
119- assertThatAttributesIdFieldIsAbsentInObject (response );
118+ assertThatAttributesIdFieldIsPresentInObject (response );
120119 }
121120
122121 @ Test
@@ -143,7 +142,7 @@ public void shouldReturnResponseWithDataAndUriSpecifiedAndUriPlaceholdersWithout
143142 assertThat (response .getMeta ().getPage ().getMaxSize (), is (25 ));
144143 assertThat (response .getMeta ().getPage ().getTotal (), is (1L ));
145144
146- assertThatAttributesIdFieldIsAbsentInObject (response );
145+ assertThatAttributesIdFieldIsPresentInObject (response );
147146 }
148147
149148
@@ -373,15 +372,15 @@ public void shouldParseJsonResponseWithListData() {
373372
374373 assertThat (response .getData ().get (0 ).getType (), is ("cars" ));
375374 assertThat (response .getData ().get (0 ).getId (), is ("M5" ));
376- assertThat (response .getData ().get (0 ).getAttributes ().getId (), nullValue ());
377375 assertThat (response .getData ().get (0 ).getAttributes ().getBrand (), is ("BMW" ));
378376
379377 assertThat (response .getData ().get (1 ).getType (), is ("cars" ));
380378 assertThat (response .getData ().get (1 ).getId (), is ("911" ));
381- assertThat (response .getData ().get (1 ).getAttributes ().getId (), nullValue ());
382379 assertThat (response .getData ().get (1 ).getAttributes ().getBrand (), is ("Porshe" ));
383380
384381 assertThat (response .getMeta ().getApi ().getVersion (), is ("1" ));
382+
383+ assertThatAttributesIdFieldIsPresentInCollection (response );
385384 }
386385
387386 @ Test
@@ -410,10 +409,11 @@ public void shouldParseJsonResponseWithSingleObjectData() {
410409
411410 assertThat (response .getData ().getType (), is ("cars" ));
412411 assertThat (response .getData ().getId (), is ("M5" ));
413- assertThat (response .getData ().getAttributes ().getId (), nullValue ());
414412 assertThat (response .getData ().getAttributes ().getBrand (), is ("BMW" ));
415413
416414 assertThat (response .getMeta ().getApi ().getVersion (), is ("1" ));
415+
416+ assertThatAttributesIdFieldIsPresentInObject (response );
417417 }
418418
419419 @ lombok .Data
@@ -519,27 +519,27 @@ private void assertErrorResponse(final @NonNull Response<?> response) {
519519 }
520520
521521 @ SuppressWarnings ("unchecked" )
522- private void assertThatAttributesIdFieldIsAbsentInCollection (final @ NonNull Response < List < Data < TestDto >>> response ) {
522+ private void assertThatAttributesIdFieldIsPresentInCollection (final @ NonNull Object response ) {
523523 final Map <String , Object > responseMap = objectMapper .convertValue (response , Map .class );
524524
525525 ((List <Object >)responseMap .get ("data" )).forEach (dataItem -> {
526526 final Object idAttributeField = ((Map <String , Object >)((Map <String , Object >)dataItem )
527527 .get ("attributes" ))
528528 .get ("id" );
529529
530- assertThat (idAttributeField , nullValue ());
530+ assertThat (idAttributeField , notNullValue ());
531531 });
532532 }
533533
534534 @ SuppressWarnings ("unchecked" )
535- private void assertThatAttributesIdFieldIsAbsentInObject (final @ NonNull Response < Data < TestDto >> response ) {
535+ private void assertThatAttributesIdFieldIsPresentInObject (final @ NonNull Object response ) {
536536 final Map <String , Object > responseMap = objectMapper .convertValue (response , Map .class );
537537
538538 final Object idAttributeField = ((Map <String , Object >)((Map <String , Object >)responseMap
539539 .get ("data" ))
540540 .get ("attributes" ))
541541 .get ("id" );
542542
543- assertThat (idAttributeField , nullValue ());
543+ assertThat (idAttributeField , notNullValue ());
544544 }
545545}
0 commit comments