public interface ResultActions
See static factory methods in
MockMvcResultMatchers
and
MockMvcResultHandlers
.
Modifier and Type | Method and Description |
---|---|
ResultActions |
andDo(ResultHandler handler)
Perform a general action.
|
ResultActions |
andExpect(ResultMatcher matcher)
Perform an expectation.
|
default ResultActions |
andExpectAll(ResultMatcher... matchers)
Perform multiple expectations, with the guarantee that all expectations
will be asserted even if one or more expectations fail with an exception.
|
MvcResult |
andReturn()
Return the result of the executed request for direct access to the results.
|
ResultActions andExpect(ResultMatcher matcher) throws Exception
You can invoke andExpect()
multiple times as in the following
example.
// static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/person/1")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.person.name").value("Jason"));
Exception
andExpectAll(ResultMatcher...)
default ResultActions andExpectAll(ResultMatcher... matchers) throws Exception
If a single Error
or Exception
is thrown, it will
be rethrown.
If multiple exceptions are thrown, this method will throw an
AssertionError
whose error message is a summary of all the
exceptions. In addition, each exception will be added as a
suppressed exception to
the AssertionError
.
This feature is similar to the SoftAssertions
support in AssertJ
and the assertAll()
support in JUnit Jupiter.
Instead of invoking andExpect()
multiple times, you can invoke
andExpectAll()
as in the following example.
// static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/person/1")) .andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON), jsonPath("$.person.name").value("Jason") );
Exception
andExpect(ResultMatcher)
ResultActions andDo(ResultHandler handler) throws Exception
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/form")).andDo(print());
Exception
MvcResult andReturn()