Skip to content

Add status ResultMatcher to express status code ranges [SPR-11424] #16051

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-11424 and commented

The status() method of MockMvcResultMatchers exposes a method per status code. This works fine if I want to express a particular code expected.

However, if I want to express a certain type of code (e.g. 1xx, 2xx etc.) I have to fall back to something like this:

….andExpect(status().is(both(greaterThanOrEqualTo(200)).and(lessThan(300))));

A short

–.andExpect(status().inRangeSuccess()); // expecting 2xx

would be easier to write and read. The method could also be named isSuccess() but I think it might make sense to clearly separate the range check methods from the ones checking for an individual status code.


Affects: 4.0.1

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions