Skip to content

Commit 9550006

Browse files
committed
Add getRawStatusCode() to ExchangeResult
Closes gh-23630
1 parent 99d9dac commit 9550006

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public MockClientHttpResponse(HttpStatus status) {
6464
}
6565

6666
public MockClientHttpResponse(int status) {
67-
Assert.isTrue(status >= 100 && status < 600, "Status must be between 1xx and 5xx");
67+
Assert.isTrue(status > 99 && status < 1000, "Status must be between 100 and 999");
6868
this.status = status;
6969
}
7070

spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -161,6 +161,15 @@ public HttpStatus getStatus() {
161161
return this.response.getStatusCode();
162162
}
163163

164+
/**
165+
* Return the HTTP status code (potentially non-standard and not resolvable
166+
* through the {@link HttpStatus} enum) as an integer.
167+
* @since 5.1.10
168+
*/
169+
public int getRawStatusCode() {
170+
return this.response.getRawStatusCode();
171+
}
172+
164173
/**
165174
* Return the response headers received from the server.
166175
*/

spring-test/src/main/java/org/springframework/test/web/reactive/server/StatusAssertions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ public WebTestClient.ResponseSpec isEqualTo(HttpStatus status) {
5555
* Assert the response status as an integer.
5656
*/
5757
public WebTestClient.ResponseSpec isEqualTo(int status) {
58-
int actual = this.exchangeResult.getStatus().value();
58+
int actual = this.exchangeResult.getRawStatusCode();
5959
this.exchangeResult.assertWithDiagnostics(() -> AssertionErrors.assertEquals("Status", status, actual));
6060
return this.responseSpec;
6161
}

spring-test/src/test/java/org/springframework/test/web/reactive/server/StatusAssertionTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,6 +62,11 @@ public void isEqualTo() {
6262
}
6363
}
6464

65+
@Test // gh-23630
66+
public void isEqualToWithCustomStatus() {
67+
statusAssertions(600).isEqualTo(600);
68+
}
69+
6570
@Test
6671
public void reasonEquals() {
6772
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
@@ -177,6 +182,10 @@ public void matches() {
177182

178183

179184
private StatusAssertions statusAssertions(HttpStatus status) {
185+
return statusAssertions(status.value());
186+
}
187+
188+
private StatusAssertions statusAssertions(int status) {
180189
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/"));
181190
MockClientHttpResponse response = new MockClientHttpResponse(status);
182191

0 commit comments

Comments
 (0)