public class HandlerResultMatchers extends ObjectSE
このクラスのインスタンスは通常、MockMvcResultMatchers.handler()
を介してアクセスされます。
注意 : リクエストの処理に使用されるコントローラーメソッドをアサートする期待は、RequestMappingHandlerMapping
および RequestMappingHandlerAdapter
で処理されたリクエストに対してのみ機能します。RequestMappingHandlerAdapter
は、Spring MVC Java 構成および XML 名前空間でデフォルトで使用されます。
修飾子 | コンストラクターと説明 |
---|---|
protected | HandlerResultMatchers() protected コンストラクター。 |
修飾子と型 | メソッドと説明 |
---|---|
ResultMatcher | handlerType(ClassSE<?> type) リクエストを処理したハンドラーの型をアサートします。 |
ResultMatcher | method(MethodSE method) リクエストの処理に使用されるコントローラーメソッドをアサートします。 |
ResultMatcher | methodCall(ObjectSE obj) リクエストの処理に使用されるコントローラーメソッドをアサートします。 |
ResultMatcher | methodName(Matcher<? super StringSE> matcher) 指定された Hamcrest Matcher を使用してリクエストを処理するために使用されるコントローラーメソッドの名前をアサートします。 |
ResultMatcher | methodName(StringSE name) リクエストの処理に使用されるコントローラーメソッドの名前をアサートします。 |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
protected HandlerResultMatchers()
MockMvcResultMatchers.handler()
を使用します。public ResultMatcher handlerType(ClassSE<?> type)
public ResultMatcher methodCall(ObjectSE obj)
期待されるメソッドは、MvcUriComponentsBuilder.fromMethodCall(Object)
と同様の「モック」コントローラーメソッド呼び出しによって指定されます。
例: このコントローラーを指定:
@RestController public class SimpleController { @RequestMapping("/") public ResponseEntity<Void> handle() { return ResponseEntity.ok().build(); } }
MvcUriComponentsBuilder.on(java.lang.Class<T>)
を静的にインポートしたテストは、次のように実行できます。
mockMvc.perform(get("/")) .andExpect(handler().methodCall(on(SimpleController.class).handle()));
obj
- 「モック」コントローラー呼び出しから返された値、または呼び出し後の「モック」コントローラー自体 public ResultMatcher methodName(Matcher<? super StringSE> matcher)
Matcher
を使用してリクエストを処理するために使用されるコントローラーメソッドの名前をアサートします。public ResultMatcher methodName(StringSE name)
public ResultMatcher method(MethodSE method)