Closed
Description
We are currently in the middle of migrating to spring 6 (via Spring Boot 3)
In Spring 5 we checked the error Message in SpringBoot Tests like this:
this.mvc.perform(put("/badUrl/abcde"))
.andExpect(status().isBadRequest())
.andExpect(result -> assertThat(result.getResponse().getErrorMessage()).isEqualTo(ERROR_MSG));
Now with the change to ErrorDetail weg cannot get the error Message via the getErrorMessage() Method:
MockHttpServletResponse:
Status = 400
Error message = null
Headers = [Vary:"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers", Content-Type:"application/problem+json", X-Content-Type-Options:"nosniff", X-XSS-Protection:"0", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0", X-Frame-Options:"DENY"]
Content type = application/problem+json
Body = {"type":"about:blank","title":"Bad Request","status":400,"detail":"Fehler beim Zuweisen. Es wurden keine Änderungen der durchgeführt.","instance":"/badUrl/abcde"}
Forwarded URL = null
Redirected URL = null
Cookies = []
org.opentest4j.AssertionFailedError:
expected: "Fehler beim Zuweisen. Es wurden keine Änderungen der durchgeführt."
but was: null
Expected :"Fehler beim Zuweisen. Es wurden keine Änderungen der durchgeführt."
Actual :null
Now the workaround would be validate the JSON and get the detail field manually, but I would expect the MockMvc Result to handle this. Otherwise the get ErrorMessage is highly misleading. Or am I misunderstanding something here?