@@ -300,10 +300,8 @@ public <T> FluxExchangeResult<T> decodeBody(ResolvableType elementType) {
300
300
}
301
301
302
302
public EntityExchangeResult <Void > consumeEmpty () {
303
- assertWithDiagnostics (() -> {
304
- DataBuffer buffer = this .response .body (toDataBuffers ()).blockFirst (getTimeout ());
305
- assertTrue ("Expected empty body" , buffer == null );
306
- });
303
+ DataBuffer buffer = this .response .body (toDataBuffers ()).blockFirst (getTimeout ());
304
+ assertWithDiagnostics (() -> assertTrue ("Expected empty body" , buffer == null ));
307
305
return new EntityExchangeResult <>(this , null );
308
306
}
309
307
}
@@ -344,10 +342,8 @@ public BodySpec expectBody() {
344
342
345
343
@ Override
346
344
public ResponseSpec consumeWith (Consumer <ExchangeResult > consumer ) {
347
- return this .result .assertWithDiagnosticsAndReturn (() -> {
348
- consumer .accept (this .result );
349
- return this ;
350
- });
345
+ this .result .assertWithDiagnostics (() -> consumer .accept (this .result ));
346
+ return this ;
351
347
}
352
348
353
349
@ Override
@@ -402,10 +398,9 @@ public DefaultSingleValueBodySpec(EntityExchangeResult<?> result) {
402
398
403
399
@ Override
404
400
public <T > EntityExchangeResult <T > isEqualTo (T expected ) {
405
- return this .result .assertWithDiagnosticsAndReturn (() -> {
406
- assertEquals ("Response body" , expected , this .result .getResponseBody ());
407
- return returnResult ();
408
- });
401
+ Object actual = this .result .getResponseBody ();
402
+ this .result .assertWithDiagnostics (() -> assertEquals ("Response body" , expected , actual ));
403
+ return returnResult ();
409
404
}
410
405
411
406
@ SuppressWarnings ("unchecked" )
@@ -427,10 +422,9 @@ public DefaultListBodySpec(EntityExchangeResult<List<?>> result) {
427
422
428
423
@ Override
429
424
public <T > EntityExchangeResult <List <T >> isEqualTo (List <T > expected ) {
430
- return this .result .assertWithDiagnosticsAndReturn (() -> {
431
- assertEquals ("Response body" , expected , this .result .getResponseBody ());
432
- return returnResult ();
433
- });
425
+ List <?> actual = this .result .getResponseBody ();
426
+ this .result .assertWithDiagnostics (() -> assertEquals ("Response body" , expected , actual ));
427
+ return returnResult ();
434
428
}
435
429
436
430
@ Override
@@ -440,21 +434,19 @@ public ListBodySpec hasSize(int size) {
440
434
441
435
@ Override
442
436
public ListBodySpec contains (Object ... elements ) {
443
- this .result .assertWithDiagnostics (() -> {
444
- List <Object > elementList = Arrays .asList (elements );
445
- String message = "Response body does not contain " + elementList ;
446
- assertTrue (message , this .result .getResponseBody ().containsAll (elementList ));
447
- });
437
+ List <?> expected = Arrays .asList (elements );
438
+ List <?> actual = this .result .getResponseBody ();
439
+ String message = "Response body does not contain " + expected ;
440
+ this .result .assertWithDiagnostics (() -> assertTrue (message , actual .containsAll (expected )));
448
441
return this ;
449
442
}
450
443
451
444
@ Override
452
445
public ListBodySpec doesNotContain (Object ... elements ) {
453
- this .result .assertWithDiagnostics (() -> {
454
- List <Object > elementList = Arrays .asList (elements );
455
- String message = "Response body should have contained " + elementList ;
456
- assertTrue (message , !this .result .getResponseBody ().containsAll (Arrays .asList (elements )));
457
- });
446
+ List <?> expected = Arrays .asList (elements );
447
+ List <?> actual = this .result .getResponseBody ();
448
+ String message = "Response body should have contained " + expected ;
449
+ this .result .assertWithDiagnostics (() -> assertTrue (message , !actual .containsAll (expected )));
458
450
return this ;
459
451
}
460
452
@@ -507,43 +499,38 @@ public DefaultMapBodySpec(EntityExchangeResult<Map<?, ?>> result) {
507
499
508
500
@ Override
509
501
public <K , V > EntityExchangeResult <Map <K , V >> isEqualTo (Map <K , V > expected ) {
510
- return this .result .assertWithDiagnosticsAndReturn (() -> {
511
- assertEquals ("Response body map" , expected , getBody ());
512
- return returnResult ();
513
- });
502
+ String message = "Response body map" ;
503
+ this .result .assertWithDiagnostics (() -> assertEquals (message , expected , getBody ()));
504
+ return returnResult ();
514
505
}
515
506
516
507
@ Override
517
508
public MapBodySpec hasSize (int size ) {
518
- return this .result .assertWithDiagnosticsAndReturn (() -> {
519
- assertEquals ("Response body map size" , size , getBody ().size ());
520
- return this ;
521
- });
509
+ String message = "Response body map size" ;
510
+ this .result .assertWithDiagnostics (() -> assertEquals (message , size , getBody ().size ()));
511
+ return this ;
522
512
}
523
513
524
514
@ Override
525
515
public MapBodySpec contains (Object key , Object value ) {
526
- return this .result .assertWithDiagnosticsAndReturn (() -> {
527
- assertEquals ("Response body map value for key " + key , value , getBody ().get (key ));
528
- return this ;
529
- });
516
+ String message = "Response body map value for key " + key ;
517
+ this .result .assertWithDiagnostics (() -> assertEquals (message , value , getBody ().get (key )));
518
+ return this ;
530
519
}
531
520
532
521
@ Override
533
522
public MapBodySpec containsKeys (Object ... keys ) {
534
- return this .result .assertWithDiagnosticsAndReturn (() -> {
535
- List <?> missing = Arrays .stream (keys ).filter (k -> !getBody ().containsKey (k )).collect (toList ());
536
- assertTrue ("Response body map does not contain keys " + missing , missing .isEmpty ());
537
- return this ;
538
- });
523
+ List <?> missing = Arrays .stream (keys ).filter (k -> !getBody ().containsKey (k )).collect (toList ());
524
+ String message = "Response body map does not contain keys " + missing ;
525
+ this .result .assertWithDiagnostics (() -> assertTrue (message , missing .isEmpty ()));
526
+ return this ;
539
527
}
540
528
541
529
@ Override
542
530
public MapBodySpec containsValues (Object ... values ) {
543
- this .result .assertWithDiagnostics (() -> {
544
- List <?> missing = Arrays .stream (values ).filter (v -> !getBody ().containsValue (v )).collect (toList ());
545
- assertTrue ("Response body map does not contain values " + missing , missing .isEmpty ());
546
- });
531
+ List <?> missing = Arrays .stream (values ).filter (v -> !getBody ().containsValue (v )).collect (toList ());
532
+ String message = "Response body map does not contain values " + missing ;
533
+ this .result .assertWithDiagnostics (() -> assertTrue (message , missing .isEmpty ()));
547
534
return this ;
548
535
}
549
536
0 commit comments