Ответ 1
Вы можете использовать метод status.reason().
Например:
@Test
public void loginWithBadCredentials() {
this.mockMvc.perform(
post("/rest/login")
.contentType(MediaType.APPLICATION_JSON)
.content("{\"username\": \"baduser\", \"password\": \"invalidPassword\"}")
)
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isUnauthorized())
.andExpect(status().reason(containsString("Bad credentials")))
.andExpect(unauthenticated());
}
MockHttpServletResponse:
Status = 401
Error message = Authentication Failed: Bad credentials
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []