Add getRawStatusCode() to ExchangeResult

Closes gh-23630
This commit is contained in:
Rossen Stoyanchev
2019-09-24 12:58:52 +01:00
parent 99d9dacc4f
commit 955000699a
4 changed files with 23 additions and 5 deletions

View File

@@ -64,7 +64,7 @@ public class MockClientHttpResponse implements ClientHttpResponse {
}
public MockClientHttpResponse(int status) {
Assert.isTrue(status >= 100 && status < 600, "Status must be between 1xx and 5xx");
Assert.isTrue(status > 99 && status < 1000, "Status must be between 100 and 999");
this.status = status;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -161,6 +161,15 @@ public class ExchangeResult {
return this.response.getStatusCode();
}
/**
* Return the HTTP status code (potentially non-standard and not resolvable
* through the {@link HttpStatus} enum) as an integer.
* @since 5.1.10
*/
public int getRawStatusCode() {
return this.response.getRawStatusCode();
}
/**
* Return the response headers received from the server.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ public class StatusAssertions {
* Assert the response status as an integer.
*/
public WebTestClient.ResponseSpec isEqualTo(int status) {
int actual = this.exchangeResult.getStatus().value();
int actual = this.exchangeResult.getRawStatusCode();
this.exchangeResult.assertWithDiagnostics(() -> AssertionErrors.assertEquals("Status", status, actual));
return this.responseSpec;
}