Relative Content

Tag Archive for springmockmvcjakarta-validation

MockMvc expected 200 actual 400 – @Valid annotation not respected

We recently upgraded our application to Spring 6, java JDK21 and are now using the jakarta.validation-api. Furthermore, we have a custom class which extends ResponseEntityExceptionHandler. When we spin up our application in order to test a bad request we do indeed invoke the handleMethodArgumentNotValid() method so there is no issue outside of the test class. We are testing this method override by using a standalone mockMvc implementation within the test class. When we perform a request against the controller the @Valid should be invoked realizing that the @RequestBody has missing arguments yet the controller still returns 200.