-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Introduce generic assertion hooks in MockMvc #23330
Comments
This could be implemented as a for instance, to assert/consume status codes, we'd add this to public ResultMatcher satisfies(IntConsumer satisfyConsumer) {
return result -> satisfyConsumer.accept(result.getResponse().getStatus());
} usage example with AssertJ: this.mockMvc.perform(post("/persons"))
.andExpect(status().satisfies(code -> Assertions.assertThat(code).isBetween(100, 300))); The relevant resultmatchers seems to be most classes in
|
some of these seem to have multiple "target" that they internally use. eg. |
Indeed. The single Thanks for brainstorming though! 👍 It's good to toss around a few ideas. |
Though, perhaps it's not so bad to introduce sibling consumer methods like:
or similarly:
@simonbasle & @rstoyanchev, thoughts? |
I like more the Satisfies approach, even though is much more verbose, it is clear in its intention (just a personal opinion) |
Do you mean the variants like the following?
|
To me this looks like a duplicate of #21178 in the first place, so yes let's close it. |
Overview
As discussed in #21178 (comment), it would be possible to provide generic hooks in
MockMvc
APIs that allow one to use any assertion library of choice. Such generic hooks could even be used for purposes other than performing assertions.Due to the usefulness of such general purpose hooks, we should consider introducing them in various
MockMvc
APIs even if we do not provide specific support for a fluent assertion API such as AssertJ (see gh-21178).The introduction of such hooks would also align with similar support provided in
WebTestClient
-- for example,WebTestClient.BodySpec.value(Consumer<B>)
.Deliverables
TBD
The text was updated successfully, but these errors were encountered: