类 HandlerResultMatchers
- java.lang.Object
- org.springframework.test.web.servlet.result.HandlerResultMatchers
public class HandlerResultMatchers extends Object
Factory for assertions on the selected handler or handler method.An instance of this class is typically accessed via
MockMvcResultMatchers.handler()
.Note: Expectations that assert the controller method used to process the request work only for requests processed with
RequestMappingHandlerMapping
andRequestMappingHandlerAdapter
which is used by default with the Spring MVC Java config and XML namespace.- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev, Sam Brannen
构造器概要
构造器 限定符 构造器 说明 protected
HandlerResultMatchers()
Protected constructor.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ResultMatcher
handlerType(Class<?> type)
Assert the type of the handler that processed the request.ResultMatcher
method(Method method)
Assert the controller method used to process the request.ResultMatcher
methodCall(Object obj)
Assert the controller method used to process the request.ResultMatcher
methodName(String name)
Assert the name of the controller method used to process the request.ResultMatcher
methodName(Matcher<? super String> matcher)
Assert the name of the controller method used to process the request using the given HamcrestMatcher
.
构造器详细资料
HandlerResultMatchers
protected HandlerResultMatchers()
Protected constructor. UseMockMvcResultMatchers.handler()
.
方法详细资料
handlerType
public ResultMatcher handlerType(Class<?> type)
Assert the type of the handler that processed the request.
methodCall
public ResultMatcher methodCall(Object obj)
Assert the controller method used to process the request.The expected method is specified through a "mock" controller method invocation similar to
MvcUriComponentsBuilder.fromMethodCall(Object)
.For example, given this controller:
@RestController public class SimpleController { @RequestMapping("/") public ResponseEntity
handle() { return ResponseEntity.ok().build(); } } A test that has statically imported
MvcUriComponentsBuilder.on(java.lang.Class<T>)
can be performed as follows:mockMvc.perform(get("/")) .andExpect(handler().methodCall(on(SimpleController.class).handle()));
- 参数:
obj
- either the value returned from a "mock" controller invocation or the "mock" controller itself after an invocation
methodName
public ResultMatcher methodName(Matcher<? super String> matcher)
Assert the name of the controller method used to process the request using the given HamcrestMatcher
.
methodName
public ResultMatcher methodName(String name)
Assert the name of the controller method used to process the request.
method
public ResultMatcher method(Method method)
Assert the controller method used to process the request.