KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > validator > test > ValidatorTest


1 //$Id: ValidatorTest.java,v 1.1 2005/05/27 08:58:54 epbernard Exp $
2
package org.hibernate.validator.test;
3
4 import java.util.Locale JavaDoc;
5 import java.util.ResourceBundle JavaDoc;
6
7 import junit.framework.TestCase;
8 import org.hibernate.validator.ClassValidator;
9 import org.hibernate.validator.InvalidValue;
10
11 /**
12  * @author Gavin King
13  */

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