1 21 22 23 package org.apache.commons.validator; 24 25 import java.io.IOException ; 26 import java.util.Locale ; 27 28 import junit.framework.Test; 29 import junit.framework.TestSuite; 30 31 import org.xml.sax.SAXException ; 32 33 36 public class LocaleTest extends TestCommon { 37 38 42 protected static String FORM_KEY = "nameForm"; 43 44 47 protected static String ACTION = "required"; 48 49 50 public LocaleTest(String name) { 51 super(name); 52 } 53 54 59 public static void main(String [] theArgs) { 60 junit.awtui.TestRunner.main(new String [] {LocaleTest.class.getName()}); 61 } 62 63 67 public static Test suite() { 68 return new TestSuite(LocaleTest.class); 70 } 71 72 76 protected void setUp() throws IOException , SAXException { 77 loadResources("validator-locale.xml"); 79 } 80 81 protected void tearDown() { 82 } 83 84 87 public void testLocale1() throws ValidatorException { 88 NameBean name = new NameBean(); 90 name.setFirstName(""); 91 name.setLastName(""); 92 93 valueTest(name, new Locale ("en", "US", "TEST1"), false, false); 94 } 95 96 99 public void testLocale2() throws ValidatorException { 100 NameBean name = new NameBean(); 102 name.setFirstName(""); 103 name.setLastName(""); 104 105 valueTest(name, new Locale ("en", "US", "TEST2"), true, false); 106 } 107 108 111 public void testLocale3() throws ValidatorException { 112 NameBean name = new NameBean(); 114 name.setFirstName(""); 115 name.setLastName(""); 116 117 valueTest(name, new Locale ("en", "UK"), false, true); 118 } 119 120 126 private void valueTest(Object name, Locale loc, boolean firstGood, boolean lastGood) 127 throws ValidatorException { 128 129 Validator validator = new Validator(resources, FORM_KEY); 132 validator.setParameter(Validator.BEAN_PARAM, name); 135 validator.setParameter(Validator.LOCALE_PARAM, loc); 136 ValidatorResults results = null; 138 139 results = validator.validate(); 144 145 assertNotNull("Results are null.", results); 146 147 ValidatorResult resultlast = results.getValidatorResult("lastName"); 148 ValidatorResult resultfirst = results.getValidatorResult("firstName"); 149 150 if (firstGood) { 151 assertNull(resultfirst); 152 } else { 153 assertNotNull(resultfirst); 154 } 155 156 if (lastGood) { 157 assertNull(resultlast); 158 } else { 159 assertNotNull(resultlast); 160 } 161 } 162 } 163 | Popular Tags |