Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toast38coza/10956173 to your computer and use it in GitHub Desktop.
Save toast38coza/10956173 to your computer and use it in GitHub Desktop.
Unit testing a Spring.io Validator class with ValidationContext
@Test
public void testValidateInitialDetailsCapture() {
MyModel myModel = new MyModel();
// setup:
MyModel.setSomeField("Some Value");
// this is the line that stumped me
ValidationContext validationContext = new DefaultValidationContext(requestContext, null, null);
MyModelValidator myModelValidator = new MyModelValidator();
myModelValidator.validateInitialSomeState(
myModel, validationContext);
MessageContext messages = requestContext.getMessageContext();
assertEquals(1, messages.getAllMessages().length);
//... other assertions go here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment