Let's say I have a model class like this:
public class User {
@NotEmpty(message = "Email is required")
private String email;
}
I want to be able to unit test for the custom error message "Email is required"
So far, I have this Unit Test code which works, but does not check for the error message.
@Test
public void should_respond_bad_request_with_errors_when_invalid() throws Exception
{
mock().perform(post("/registration/new"))
.andExpect(status().isBadRequest())
.andExpect(view().name("registration-form"))
.andExpect(model().attributeHasFieldErrors("user", "email"));
}