Author: amarkhel
Date: 2008-07-08 10:58:16 -0400 (Tue, 08 Jul 2008)
New Revision: 9453
Modified:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/validator/BeanValidator.java
trunk/sandbox/ui/beanValidator/src/test/java/org/richfaces/validator/BeanValidatorTest.java
Log:
Refactor JUnits for beanValidator
Modified:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/validator/BeanValidator.java
===================================================================
---
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/validator/BeanValidator.java 2008-07-08
14:43:11 UTC (rev 9452)
+++
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/validator/BeanValidator.java 2008-07-08
14:58:16 UTC (rev 9453)
@@ -29,6 +29,8 @@
*/
public class BeanValidator {
+ private static final String RESOURCE_BUNDLE_IS_NOT_REGISTERED_FOR_CURRENT_LOCALE =
"Resource bundle is not registered for current locale";
+
private static final String FACES_CONTEXT_IS_NULL = "Faces context is null";
private static final String INPUT_PARAMETERS_IS_NOT_CORRECT = "Input parameters is
not correct.";
@@ -206,6 +208,9 @@
// TODO - cache validator instances.
// TODO - localization support.
ResourceBundle bundle = getCurrentResourceBundle(locale);
+ if(null == bundle){
+ throw new FacesException(RESOURCE_BUNDLE_IS_NOT_REGISTERED_FOR_CURRENT_LOCALE);
+ }
ValidatorKey key = new ValidatorKey(beanClass, bundle);
ClassValidator result = classValidators.get(key);
if (null == result) {
@@ -225,6 +230,9 @@
}
String appBundle = FacesContext.getCurrentInstance().getApplication()
.getMessageBundle();
+ if(null == appBundle || null == locale){
+ return null;
+ }
ResourceBundle bundle = ResourceBundle.getBundle(appBundle, locale);
return bundle;
}
Modified:
trunk/sandbox/ui/beanValidator/src/test/java/org/richfaces/validator/BeanValidatorTest.java
===================================================================
---
trunk/sandbox/ui/beanValidator/src/test/java/org/richfaces/validator/BeanValidatorTest.java 2008-07-08
14:43:11 UTC (rev 9452)
+++
trunk/sandbox/ui/beanValidator/src/test/java/org/richfaces/validator/BeanValidatorTest.java 2008-07-08
14:58:16 UTC (rev 9453)
@@ -2,20 +2,31 @@
import java.util.Locale;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
-import junit.framework.TestCase;
+public class BeanValidatorTest extends AbstractAjax4JsfTestCase {
-public class BeanValidatorTest extends TestCase {
+ public BeanValidatorTest(String name) {
+ super(name);
+ }
public void testValidate() {
}
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
public void testGetValidator() throws Exception {
BeanValidator beanValidator = BeanValidator.createInstance();
- ClassValidator<? extends Object> validator =
beanValidator.getValidator(ValidableBean.class,Locale.getDefault());
+ ClassValidator<? extends Object> validator =
beanValidator.getValidator(ValidableBean.class,Locale.ENGLISH);
assertNotNull(validator);
assertTrue(validator.hasValidationRules());
validator = beanValidator.getValidator(String.class,Locale.getDefault());