I have the following controller:
@RestController
@RequestMapping(value = ROOT_MAPPING)
public class GatewayController {
BindingResult
is not a bean in the ApplicationContext
. Thus, you cannot mock it via @MockBean
.
A BindingResult
is created for you by Spring MVC for each incoming HTTP request.
Thus, you don't want to mock the BindingResult
. In fact, you probably don't want to mock the behavior of your RequestValidator
either. Rather, you should ideally use the real implementation of your RequestValidator
, pass in invalid request data (via MockMvc
), and then verify the response accordingly.
Note that you should be able to include the real implementation of your RequestValidator
via @Import(RequestValidator.class)
on the test class.