51
51
import org .springframework .util .StringUtils ;
52
52
import org .springframework .web .reactive .HandlerMapping ;
53
53
import org .springframework .web .server .MethodNotAllowedException ;
54
+ import org .springframework .web .server .ResponseStatusException ;
54
55
import org .springframework .web .server .ServerWebExchange ;
55
56
57
+ import static org .hamcrest .Matchers .instanceOf ;
56
58
import static org .junit .Assert .assertEquals ;
57
59
import static org .junit .Assert .assertNull ;
58
60
import static org .junit .Assert .assertSame ;
61
+ import static org .junit .Assert .assertThat ;
59
62
import static org .junit .Assert .assertTrue ;
60
63
import static org .junit .Assert .fail ;
61
64
@@ -273,11 +276,14 @@ private void testInvalidPath(HttpMethod httpMethod, String requestPath, Resource
273
276
MockServerHttpRequest request = MockServerHttpRequest .method (httpMethod , "" ).build ();
274
277
ServerWebExchange exchange = MockServerWebExchange .from (request );
275
278
setPathWithinHandlerMapping (exchange , requestPath );
276
- this .handler .handle (exchange ).block (TIMEOUT );
279
+ StepVerifier .create (this .handler .handle (exchange ))
280
+ .expectErrorSatisfies (err -> {
281
+ assertThat (err , instanceOf (ResponseStatusException .class ));
282
+ assertEquals (HttpStatus .NOT_FOUND , ((ResponseStatusException ) err ).getStatus ());
283
+ }).verify (TIMEOUT );
277
284
if (!location .createRelative (requestPath ).exists () && !requestPath .contains (":" )) {
278
285
fail (requestPath + " doesn't actually exist as a relative path" );
279
286
}
280
- assertEquals (HttpStatus .NOT_FOUND , exchange .getResponse ().getStatusCode ());
281
287
}
282
288
283
289
@ Test
@@ -363,8 +369,11 @@ public void modified() throws Exception {
363
369
public void directory () throws Exception {
364
370
MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("" ).build ());
365
371
setPathWithinHandlerMapping (exchange , "js/" );
366
- this .handler .handle (exchange ).block (TIMEOUT );
367
- assertEquals (HttpStatus .NOT_FOUND , exchange .getResponse ().getStatusCode ());
372
+ StepVerifier .create (this .handler .handle (exchange ))
373
+ .expectErrorSatisfies (err -> {
374
+ assertThat (err , instanceOf (ResponseStatusException .class ));
375
+ assertEquals (HttpStatus .NOT_FOUND , ((ResponseStatusException ) err ).getStatus ());
376
+ }).verify (TIMEOUT );
368
377
}
369
378
370
379
@ Test
@@ -381,8 +390,11 @@ public void directoryInJarFile() throws Exception {
381
390
public void missingResourcePath () throws Exception {
382
391
MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("" ).build ());
383
392
setPathWithinHandlerMapping (exchange , "" );
384
- this .handler .handle (exchange ).block (TIMEOUT );
385
- assertEquals (HttpStatus .NOT_FOUND , exchange .getResponse ().getStatusCode ());
393
+ StepVerifier .create (this .handler .handle (exchange ))
394
+ .expectErrorSatisfies (err -> {
395
+ assertThat (err , instanceOf (ResponseStatusException .class ));
396
+ assertEquals (HttpStatus .NOT_FOUND , ((ResponseStatusException ) err ).getStatus ());
397
+ }).verify (TIMEOUT );
386
398
}
387
399
388
400
@ Test (expected = IllegalArgumentException .class )
@@ -409,8 +421,11 @@ private void resourceNotFound(HttpMethod httpMethod) throws Exception {
409
421
MockServerHttpRequest request = MockServerHttpRequest .method (httpMethod , "" ).build ();
410
422
MockServerWebExchange exchange = MockServerWebExchange .from (request );
411
423
setPathWithinHandlerMapping (exchange , "not-there.css" );
412
- this .handler .handle (exchange ).block (TIMEOUT );
413
- assertEquals (HttpStatus .NOT_FOUND , exchange .getResponse ().getStatusCode ());
424
+ StepVerifier .create (this .handler .handle (exchange ))
425
+ .expectErrorSatisfies (err -> {
426
+ assertThat (err , instanceOf (ResponseStatusException .class ));
427
+ assertEquals (HttpStatus .NOT_FOUND , ((ResponseStatusException ) err ).getStatus ());
428
+ }).verify (TIMEOUT );
414
429
}
415
430
416
431
@ Test
0 commit comments