1 package org.hibernate.validator.test; 3 4 import java.util.Locale ; 5 import java.util.ResourceBundle ; 6 7 import junit.framework.TestCase; 8 import org.hibernate.validator.ClassValidator; 9 import org.hibernate.validator.InvalidValue; 10 11 14 public class ValidatorTest extends TestCase { 15 public void testValidator() { 16 Address a = new Address(); 17 a.setCountry("Australia"); 18 a.setZip("1221341234123"); 19 a.setState("Vic"); 20 a.setLine1("Karbarook Ave"); 21 a.setId(3); 22 ClassValidator classValidator = new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ); 23 InvalidValue[] validationMessages = classValidator.getInvalidValues(a); 24 assertEquals( validationMessages.length, 1 ); 25 a.setZip(null); 26 a.setState("Victoria"); 27 validationMessages = classValidator.getInvalidValues(a); 28 assertEquals( validationMessages.length, 2 ); 29 a.setZip("3181"); 30 a.setState("NSW"); 31 validationMessages = classValidator.getInvalidValues(a); 32 assertEquals( validationMessages.length, 0 ); 33 } 34 } 35 | Popular Tags |