Author: amarkhel
Date: 2008-07-08 11:20:31 -0400 (Tue, 08 Jul 2008)
New Revision: 9456
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 JUnit
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
15:13:17 UTC (rev 9455)
+++
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/validator/BeanValidator.java 2008-07-08
15:20:31 UTC (rev 9456)
@@ -207,14 +207,10 @@
Class<? extends Object> beanClass, Locale locale) {
// 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);
+ ValidatorKey key = new ValidatorKey(beanClass, locale);
ClassValidator result = classValidators.get(key);
if (null == result) {
- result = createValidator(beanClass, bundle);
+ result = createValidator(beanClass, locale);
classValidators.put(key, result);
}
return result;
@@ -244,7 +240,8 @@
*/
@SuppressWarnings("unchecked")
private ClassValidator<? extends Object> createValidator(
- Class<? extends Object> beanClass, ResourceBundle bundle) {
+ Class<? extends Object> beanClass, Locale locale) {
+ ResourceBundle bundle = getCurrentResourceBundle(locale);
return bundle == null ? new ClassValidator(beanClass)
: new ClassValidator(beanClass, bundle);
}
@@ -375,7 +372,7 @@
*/
class ValidatorKey {
private Class<? extends Object> validatableClass;
- private ResourceBundle bundle;
+ private Locale locale;
/**
* Constructor for ValidatorKey object
@@ -386,21 +383,21 @@
* Resource bundle, used during validation process
*/
public ValidatorKey(Class<? extends Object> validatableClass,
- ResourceBundle bundle) {
+ Locale locale) {
this.validatableClass = validatableClass;
- this.bundle = bundle;
+ this.locale = locale;
}
@Override
public boolean equals(Object other) {
ValidatorKey key = (ValidatorKey) other;
return key.validatableClass.equals(validatableClass)
- && key.bundle.equals(bundle);
+ && key.locale.equals(locale);
}
@Override
public int hashCode() {
- return validatableClass.hashCode() + bundle.hashCode();
+ return validatableClass.hashCode() + locale.hashCode();
}
}
}
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
15:13:17 UTC (rev 9455)
+++
trunk/sandbox/ui/beanValidator/src/test/java/org/richfaces/validator/BeanValidatorTest.java 2008-07-08
15:20:31 UTC (rev 9456)
@@ -1,6 +1,7 @@
package org.richfaces.validator;
import java.util.Locale;
+import java.util.ResourceBundle;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.hibernate.validator.ClassValidator;
Show replies by date