Skip to content

Commit 27aaad5

Browse files
committed
Add isTooEarly() method to StatusResultMatchers
See gh-23384
1 parent 4f3b89e commit 27aaad5

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,14 @@ public ResultMatcher isFailedDependency() {
492492
return matcher(HttpStatus.FAILED_DEPENDENCY);
493493
}
494494

495+
/**
496+
* Assert the response status code is {@code HttpStatus.TOO_EARLY} (425).
497+
* @since 5.2
498+
*/
499+
public ResultMatcher isTooEarly() {
500+
return matcher(HttpStatus.valueOf(425));
501+
}
502+
495503
/**
496504
* Assert the response status code is {@code HttpStatus.UPGRADE_REQUIRED} (426).
497505
*/

spring-test/src/test/java/org/springframework/test/web/servlet/result/StatusResultMatchersTests.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222

23-
import org.junit.Before;
2423
import org.junit.Test;
2524

2625
import org.springframework.core.Conventions;
@@ -42,23 +41,14 @@
4241
*/
4342
public class StatusResultMatchersTests {
4443

45-
private StatusResultMatchers matchers;
44+
private final StatusResultMatchers matchers = new StatusResultMatchers();
4645

47-
private MockHttpServletRequest request;
48-
49-
50-
@Before
51-
public void setup() {
52-
this.matchers = new StatusResultMatchers();
53-
this.request = new MockHttpServletRequest();
54-
}
46+
private final MockHttpServletRequest request = new MockHttpServletRequest();
5547

5648

5749
@Test
5850
public void testHttpStatusCodeResultMatchers() throws Exception {
59-
6051
List<AssertionError> failures = new ArrayList<>();
61-
6252
for (HttpStatus status : HttpStatus.values()) {
6353
MockHttpServletResponse response = new MockHttpServletResponse();
6454
response.setStatus(status.value());
@@ -77,7 +67,6 @@ public void testHttpStatusCodeResultMatchers() throws Exception {
7767
throw new Exception("Failed to obtain ResultMatcher for status " + status, ex);
7868
}
7969
}
80-
8170
if (!failures.isEmpty()) {
8271
fail("Failed status codes: " + failures);
8372
}

0 commit comments

Comments
 (0)