Hi, I'm looking for an example how to call a validator implementation (PersonValidator) outside of a web application context and form controller (AddPersonController). I'm trying to write a test class that would excersize this PersonValidator class and verify my rules work the way I intended them to. Given:
andCode:public class Person { private String name; private int age; // the usual suspects: getters and setters }
What might my PersonValidatorTest class look like?Code:public class PersonValidator implements Validator { public boolean supports(Class clzz) { return Person.class.equals(clzz); } public void validate(Object obj, Errors e) { ValidationUtils.rejectIfEmpty(e, "name", "name.empty"); Person p = (Person)obj; if (p.getAge() < 0) { e.rejectValue("age", "negativevalue"); } else if (p.getAge() > 110) { e.rejectValue("age", "tooold"); } } }


Reply With Quote