spring-framework / org.springframework.test.web.servlet.result / HandlerResultMatchers

HandlerResultMatchers

open class HandlerResultMatchers

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 and RequestMappingHandlerAdapter which is used by default with the Spring MVC Java config and XML namespace.

Author
Rossen Stoyanchev

Author
Sam Brannen

Since
3.2

Functions

handlerType

open fun handlerType(type: Class<*>): ResultMatcher

Assert the type of the handler that processed the request.

method

open fun method(method: Method): ResultMatcher

Assert the controller method used to process the request.

methodCall

open fun methodCall(obj: Any): ResultMatcher

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 can be performed as follows:

 mockMvc.perform(get("/")) .andExpect(handler().methodCall(on(SimpleController.class).handle())); 

methodName

open fun methodName(matcher: Matcher<in String>): ResultMatcher

Assert the name of the controller method used to process the request using the given Hamcrest Matcher.

open fun methodName(name: String): ResultMatcher

Assert the name of the controller method used to process the request.