public interface ResultActions
MockMvcResultMatchers
および MockMvcResultHandlers
の静的ファクトリメソッドを参照してください。
修飾子と型 | メソッドと説明 |
---|---|
ResultActions | andDo(ResultHandler handler) 一般的なアクションを実行します。 |
ResultActions | andExpect(ResultMatcher matcher) 期待を実行します。 |
default ResultActions | andExpectAll(ResultMatcher... matchers) 1 つ以上の期待値が例外で失敗した場合でも、すべての期待値がアサートされることを保証して、複数の期待値を実行します。 |
MvcResult | andReturn() 結果に直接アクセスするために、実行されたリクエストの結果を返します。 |
ResultActions andExpect(ResultMatcher matcher) throws ExceptionSE
次の例のように、andExpect()
を複数回呼び出すことができます。
// static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/person/1")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.person.name").value("Jason"));
default ResultActions andExpectAll(ResultMatcher... matchers) throws ExceptionSE
Error
SE または Exception
SE が 1 つスローされると、再スローされます。
複数の例外がスローされた場合、このメソッドは、エラーメッセージがすべての例外の要約である AssertionError
SE をスローします。さらに、各例外は、抑制SEされた例外として AssertionError
に追加されます。
この機能は、AssertJ の SoftAssertions
サポートおよび JUnit Jupiter の assertAll()
サポートに似ています。
andExpect()
を複数回呼び出す代わりに、次の例のように andExpectAll()
を呼び出すことができます。
// static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/person/1")) .andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON), jsonPath("$.person.name").value("Jason") );
ExceptionSE
andExpect(ResultMatcher)
ResultActions andDo(ResultHandler handler) throws ExceptionSE
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/form")).andDo(print());
ExceptionSE
MvcResult andReturn()