1717import reactor .core .publisher .Mono ;
1818
1919import static de .ksbrwsk .people .Constants .API ;
20- import static org .junit .jupiter .api .Assertions .assertEquals ;
21- import static org .junit .jupiter .api .Assertions .assertNotNull ;
20+ import static org .assertj .core .api .Assertions .assertThat ;
2221import static org .mockito .ArgumentMatchers .any ;
2322import static org .mockito .Mockito .when ;
2423
@@ -46,35 +45,31 @@ void should_handle_find_all() {
4645 .uri (API )
4746 .exchange ()
4847 .expectStatus ()
49- .is2xxSuccessful ()
50- .expectBody ()
51- .jsonPath ("$[0].id" )
52- .isEqualTo ("1" )
53- .jsonPath ("$[0].name" )
54- .isEqualTo ("Name" )
55- .jsonPath ("$[1].id" )
56- .isEqualTo ("2" )
57- .jsonPath ("$[1].name" )
58- .isEqualTo ("Sabo" );
48+ .isOk ()
49+ .expectBodyList (Person .class )
50+ .hasSize (2 )
51+ .contains (
52+ new Person (1L , "Name" ),
53+ new Person (2L , "Sabo" ));
5954 }
6055
6156 @ Test
6257 @ DisplayName ("should handle request find by id x" )
6358 void should_handle_find_by_id () {
6459 when (this .personRepository .findById (1L ))
6560 .thenReturn (Mono .just (new Person (1L , "Name" )));
66- Person person = this .webTestClient
61+ this .webTestClient
6762 .get ()
6863 .uri (API + "/1" )
6964 .exchange ()
7065 .expectStatus ()
71- .is2xxSuccessful ()
66+ .isOk ()
7267 .expectBody (Person .class )
73- .returnResult ()
74- .getResponseBody ();
75- assertNotNull ( person );
76- assertEquals ( person . getName (), "Name" );
77- assertEquals ( person . getId (), 1L );
68+ .consumeWith ( response -> {
69+ assertThat ( response .getResponseBody ()). isNotNull ();
70+ assertThat ( response . getResponseBody (). getName ()). isEqualTo ( "Name" );
71+ assertThat ( response . getResponseBody (). getId ()). isEqualTo ( 1L );
72+ } );
7873 }
7974
8075 @ Test
@@ -173,7 +168,7 @@ void should_handle_update_person(String name) {
173168 .bodyValue (person )
174169 .exchange ()
175170 .expectStatus ()
176- .is2xxSuccessful ()
171+ .isOk ()
177172 .expectBody (Person .class )
178173 .isEqualTo (person );
179174 }
@@ -207,7 +202,7 @@ void should_handle_not_found() {
207202 .uri ("/api/peple" )
208203 .exchange ()
209204 .expectStatus ()
210- .is4xxClientError ();
205+ .isNotFound ();
211206 }
212207
213208 @ Test
@@ -220,7 +215,7 @@ void should_handle_find_first_by_name() {
220215 .uri (API + "/firstByName/First" )
221216 .exchange ()
222217 .expectStatus ()
223- .is2xxSuccessful ()
218+ .isOk ()
224219 .expectBody (Person .class )
225220 .isEqualTo (new Person (1L , "First" ));
226221 }
0 commit comments