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.
What has changed between spring 5 and spring 6 that we cannot utilize the MockMvc standalone to invoke @Valid in a test class? Has anyone encountered this?
We tried throwing the MethodArgumentNotValidException when the service class in the FakeController is invoked, but this will bubble up to a 500 error. This makes sense. Something must have changed between spring 5 and 6. We did see there is a boolean value in the HandlerMethod called validateArguments yet we are unable to set that true within our test class.
user25066877 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.