I have the following test that fails:
@Test
public void testValidation() {
Validator validator = new LocalValidatorFactoryBean();
Map<String, String> map = new HashMap<String, String>();
MapBindingResult errors = new MapBindingResult(map, Foo.class.getName());
Foo foo = new Foo();
foo.setBar("ba");
validator.validate(foo, errors);
assertTrue(errors.hasFieldErrors());
}
Foo is as follows:
import javax.validation.constraints.Size;
public class Foo {
@Size(min=9, max=9)
private String bar;
// ... public setter and getter for bar
}
I have referenced Manually call Spring Annotation Validation and Using Spring Validator outside of the context of Spring MVC but I'm not sure why this test is failing.