Use HttpStatusCode interface
This commit contains changes made because of the introduction of HttpStatusCode. In general, methods that used to return a HttpStatus now return HttpStatusCode instead, and methods that returned raw status codes are now deprecated. See gh-28214
This commit is contained in:
@@ -30,6 +30,7 @@ import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseCookie;
|
||||
import org.springframework.http.client.reactive.ClientHttpResponse;
|
||||
@@ -46,7 +47,7 @@ import org.springframework.util.MultiValueMap;
|
||||
*/
|
||||
public class MockClientHttpResponse implements ClientHttpResponse {
|
||||
|
||||
private final int status;
|
||||
private final HttpStatusCode statusCode;
|
||||
|
||||
private final HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
@@ -55,25 +56,25 @@ public class MockClientHttpResponse implements ClientHttpResponse {
|
||||
private Flux<DataBuffer> body = Flux.empty();
|
||||
|
||||
|
||||
public MockClientHttpResponse(HttpStatus status) {
|
||||
Assert.notNull(status, "HttpStatus is required");
|
||||
this.status = status.value();
|
||||
}
|
||||
|
||||
public MockClientHttpResponse(int status) {
|
||||
Assert.isTrue(status > 99 && status < 1000, "Status must be between 100 and 999");
|
||||
this.status = status;
|
||||
this(HttpStatusCode.valueOf(status));
|
||||
}
|
||||
|
||||
public MockClientHttpResponse(HttpStatusCode status) {
|
||||
Assert.notNull(status, "HttpStatusCode is required");
|
||||
this.statusCode = status;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HttpStatus getStatusCode() {
|
||||
return HttpStatus.valueOf(this.status);
|
||||
public HttpStatusCode getStatusCode() {
|
||||
return this.statusCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getRawStatusCode() {
|
||||
return this.status;
|
||||
return this.statusCode.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,7 +141,11 @@ public class MockClientHttpResponse implements ClientHttpResponse {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
HttpStatus code = HttpStatus.resolve(this.status);
|
||||
return (code != null ? code.name() + "(" + this.status + ")" : "Status (" + this.status + ")") + this.headers;
|
||||
if (this.statusCode instanceof HttpStatus status) {
|
||||
return status.name() + "(" + this.statusCode + ")" + this.headers;
|
||||
}
|
||||
else {
|
||||
return "Status (" + this.statusCode + ")" + this.headers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user