1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -71,8 +71,7 @@ public WebTestClient.ResponseSpec isOk() {
71
71
* Assert the response status code is {@code HttpStatus.CREATED} (201).
72
72
*/
73
73
public WebTestClient .ResponseSpec isCreated () {
74
- HttpStatus expected = HttpStatus .CREATED ;
75
- return assertStatusAndReturn (expected );
74
+ return assertStatusAndReturn (HttpStatus .CREATED );
76
75
}
77
76
78
77
/**
@@ -158,8 +157,8 @@ public WebTestClient.ResponseSpec isNotFound() {
158
157
*/
159
158
public WebTestClient .ResponseSpec reasonEquals (String reason ) {
160
159
String actual = this .exchangeResult .getStatus ().getReasonPhrase ();
161
- String message = "Response status reason" ;
162
- this . exchangeResult . assertWithDiagnostics (() -> AssertionErrors .assertEquals (message , reason , actual ));
160
+ this . exchangeResult . assertWithDiagnostics (() ->
161
+ AssertionErrors .assertEquals ("Response status reason" , reason , actual ));
163
162
return this .responseSpec ;
164
163
}
165
164
@@ -195,8 +194,7 @@ public WebTestClient.ResponseSpec is4xxClientError() {
195
194
* Assert the response status code is in the 5xx range.
196
195
*/
197
196
public WebTestClient .ResponseSpec is5xxServerError () {
198
- HttpStatus .Series expected = HttpStatus .Series .SERVER_ERROR ;
199
- return assertSeriesAndReturn (expected );
197
+ return assertSeriesAndReturn (HttpStatus .Series .SERVER_ERROR );
200
198
}
201
199
202
200
/**
@@ -205,8 +203,8 @@ public WebTestClient.ResponseSpec is5xxServerError() {
205
203
* @since 5.1
206
204
*/
207
205
public WebTestClient .ResponseSpec value (Matcher <Integer > matcher ) {
208
- int value = this .exchangeResult .getStatus (). value ();
209
- this .exchangeResult .assertWithDiagnostics (() -> MatcherAssert .assertThat ("Response status" , value , matcher ));
206
+ int actual = this .exchangeResult .getRawStatusCode ();
207
+ this .exchangeResult .assertWithDiagnostics (() -> MatcherAssert .assertThat ("Response status" , actual , matcher ));
210
208
return this .responseSpec ;
211
209
}
212
210
@@ -216,8 +214,8 @@ public WebTestClient.ResponseSpec value(Matcher<Integer> matcher) {
216
214
* @since 5.1
217
215
*/
218
216
public WebTestClient .ResponseSpec value (Consumer <Integer > consumer ) {
219
- int value = this .exchangeResult .getStatus (). value ();
220
- this .exchangeResult .assertWithDiagnostics (() -> consumer .accept (value ));
217
+ int actual = this .exchangeResult .getRawStatusCode ();
218
+ this .exchangeResult .assertWithDiagnostics (() -> consumer .accept (actual ));
221
219
return this .responseSpec ;
222
220
}
223
221
@@ -230,10 +228,8 @@ private WebTestClient.ResponseSpec assertStatusAndReturn(HttpStatus expected) {
230
228
231
229
private WebTestClient .ResponseSpec assertSeriesAndReturn (HttpStatus .Series expected ) {
232
230
HttpStatus status = this .exchangeResult .getStatus ();
233
- this .exchangeResult .assertWithDiagnostics (() -> {
234
- String message = "Range for response status value " + status ;
235
- AssertionErrors .assertEquals (message , expected , status .series ());
236
- });
231
+ this .exchangeResult .assertWithDiagnostics (() ->
232
+ AssertionErrors .assertEquals ("Range for response status value " + status , expected , status .series ()));
237
233
return this .responseSpec ;
238
234
}
239
235
0 commit comments