Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Feb 13, 2014 · 3 comments
Closed

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Feb 13, 2014

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

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 13, 2014

Rossen Stoyanchev commented

Sounds good. HttpStatus has the Series enum along those lines. We could add a method for each of them. How about:

.andExpect(status().is1xxInformational())
–.andExpect(status().is2xxSuccess())
–.andExpect(status().is3xxRedirection())
–.andExpect(status().is4xxClientError())
–.andExpect(status().is5xxServerError())

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 10, 2014

Balakrishnan commented

In the newly added methods, the order of parameters in assert seems to be reversed.

Also, would it be possible to add these helper methods in org.springframework.http.HttpStatus also? That would be quite helpful.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 12, 2014

Rossen Stoyanchev commented

thanks see these two commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants