Last active
August 29, 2015 13:59
-
-
Save toast38coza/10956173 to your computer and use it in GitHub Desktop.
Unit testing a Spring.io Validator class with ValidationContext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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