bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r996741 [1/2] - in /incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303: ./ example/ groups/ util/
Date Tue, 14 Sep 2010 02:43:59 GMT
Author: mbenson
Date: Tue Sep 14 02:43:58 2010
New Revision: 996741

URL: http://svn.apache.org/viewvc?rev=996741&view=rev
Log:
refactor tests for extensibility

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BootstrapTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/CircularReferencesTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ComposedConstraintsTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintCompositionTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/FooTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/PayloadTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidatorResolutionTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/Library.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/RecursiveFoo.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/groups/CollectionValidationTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java Tue Sep 14 02:43:58 2010
@@ -18,10 +18,22 @@
  */
 package org.apache.bval.jsr303;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import java.util.Locale;
+import java.util.Set;
 
-import javax.validation.*;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
 import javax.validation.constraints.NotNull;
 import javax.validation.groups.Default;
 import javax.validation.metadata.BeanDescriptor;
@@ -31,14 +43,8 @@ import javax.validation.metadata.Propert
 import javax.validation.metadata.Scope;
 import javax.validation.metadata.ElementDescriptor.ConstraintFinder;
 
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import java.util.Locale;
-import java.util.Set;
-
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import junit.framework.Assert;
+import junit.framework.TestCase;
 
 /**
  * Tests the implementation of {@link BeanDescriptor} and its dependent
@@ -47,7 +53,6 @@ import static java.lang.annotation.Reten
  * @author Carlos Vara
  */
 public class BeanDescriptorTest extends TestCase {
-
     static ValidatorFactory factory;
 
     static {
@@ -55,19 +60,36 @@ public class BeanDescriptorTest extends 
         ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
     }
 
-    private Validator getValidator() {
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
-    
-    
+
     /**
      * Check that groups(), message() and payload() are always in the
      * attributes.
      */
     public void testMandatoryAttributesPresentInConstraintDescriptor() {
-        Validator validator = getValidator();
-        
-        Set<ConstraintDescriptor<?>> nameDescriptors = validator.getConstraintsForClass(Form.class).getConstraintsForProperty("name").getConstraintDescriptors();
+        Set<ConstraintDescriptor<?>> nameDescriptors =
+            validator.getConstraintsForClass(Form.class).getConstraintsForProperty("name").getConstraintDescriptors();
         Assert.assertEquals("Incorrect number of descriptors", 1, nameDescriptors.size());
         ConstraintDescriptor<?> nameDescriptor = nameDescriptors.iterator().next();
         Assert.assertTrue("groups attribute not present", nameDescriptor.getAttributes().containsKey("groups"));
@@ -80,19 +102,20 @@ public class BeanDescriptorTest extends 
      * inheriting groups.
      */
     public void testCorrectValueForInheritedGroupsAttribute() {
-        Validator validator = getValidator();
-        
-        Set<ConstraintDescriptor<?>> passwordDescriptors = validator.getConstraintsForClass(Account.class).getConstraintsForProperty("password").getConstraintDescriptors();
+        Set<ConstraintDescriptor<?>> passwordDescriptors =
+            validator.getConstraintsForClass(Account.class).getConstraintsForProperty("password")
+                .getConstraintDescriptors();
         Assert.assertEquals("Incorrect number of descriptors", 1, passwordDescriptors.size());
         ConstraintDescriptor<?> passwordDescriptor = passwordDescriptors.iterator().next();
-        Assert.assertEquals("Incorrect number of composing constraints", 1, passwordDescriptor.getComposingConstraints().size());
+        Assert.assertEquals("Incorrect number of composing constraints", 1, passwordDescriptor
+            .getComposingConstraints().size());
         ConstraintDescriptor<?> notNullDescriptor = passwordDescriptor.getComposingConstraints().iterator().next();
-        
+
         // Check that the groups value containts Group1.class
         Class<?>[] notNullGroups = (Class<?>[]) notNullDescriptor.getAttributes().get("groups");
         boolean found = false;
-        for ( Class<?> group : notNullGroups ) {
-            if ( group == Group1.class ) {
+        for (Class<?> group : notNullGroups) {
+            if (group == Group1.class) {
                 found = true;
                 break;
             }
@@ -106,17 +129,19 @@ public class BeanDescriptorTest extends 
      * of the queried class.
      */
     public void testImplicitGroupIsPresent() {
-        Validator validator = getValidator();
-        
-        Set<ConstraintDescriptor<?>> nameDescriptors = validator.getConstraintsForClass(Woman.class).getConstraintsForProperty("name").getConstraintDescriptors();
+        Set<ConstraintDescriptor<?>> nameDescriptors =
+            validator.getConstraintsForClass(Woman.class).getConstraintsForProperty("name").getConstraintDescriptors();
         Assert.assertEquals("Incorrect number of descriptors", 1, nameDescriptors.size());
         ConstraintDescriptor<?> notNullDescriptor = nameDescriptors.iterator().next();
-        
-        // Check that the groups attribute value contains the implicit group Person and the Default group
+
+        // Check that the groups attribute value contains the implicit group
+        // Person and the Default group
         Class<?>[] notNullGroups = (Class<?>[]) notNullDescriptor.getAttributes().get("groups");
         Assert.assertEquals("Incorrect number of groups", 2, notNullGroups.length);
-        Assert.assertTrue("Default group not present", notNullGroups[0].equals(Default.class) || notNullGroups[1].equals(Default.class));
-        Assert.assertTrue("Implicit group not present", notNullGroups[0].equals(Person.class) || notNullGroups[1].equals(Person.class));
+        Assert.assertTrue("Default group not present", notNullGroups[0].equals(Default.class)
+            || notNullGroups[1].equals(Default.class));
+        Assert.assertTrue("Implicit group not present", notNullGroups[0].equals(Person.class)
+            || notNullGroups[1].equals(Person.class));
     }
 
     /**
@@ -124,12 +149,11 @@ public class BeanDescriptorTest extends 
      * interface group when querying the interface directly.
      */
     public void testNoImplicitGroupWhenQueryingInterfaceDirectly() {
-        Validator validator = getValidator();
-        
-        Set<ConstraintDescriptor<?>> nameDescriptors = validator.getConstraintsForClass(Person.class).getConstraintsForProperty("name").getConstraintDescriptors();
+        Set<ConstraintDescriptor<?>> nameDescriptors =
+            validator.getConstraintsForClass(Person.class).getConstraintsForProperty("name").getConstraintDescriptors();
         Assert.assertEquals("Incorrect number of descriptors", 1, nameDescriptors.size());
         ConstraintDescriptor<?> notNullDescriptor = nameDescriptors.iterator().next();
-        
+
         // Check that only the default group is present
         Class<?>[] notNullGroups = (Class<?>[]) notNullDescriptor.getAttributes().get("groups");
         Assert.assertEquals("Incorrect number of groups", 1, notNullGroups.length);
@@ -141,11 +165,9 @@ public class BeanDescriptorTest extends 
      * {@link ElementDescriptor#getElementClass()} work as defined in the spec.
      */
     public void testElementDescriptorGetElementClass() {
-        Validator validator = getValidator();
-        
-        BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Person.class );
+        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(Person.class);
         Assert.assertEquals("Incorrect class returned", Person.class, beanDescriptor.getElementClass());
-        
+
         PropertyDescriptor nameDescriptor = beanDescriptor.getConstraintsForProperty("name");
         Assert.assertEquals("Incorrect class returned", String.class, nameDescriptor.getElementClass());
     }
@@ -155,57 +177,58 @@ public class BeanDescriptorTest extends 
      * {@link ConstraintFinder#lookingAt(javax.validation.metadata.Scope)}.
      */
     public void testConstraintFinderLookingAt() {
-        Validator validator = getValidator();
-        
-        PropertyDescriptor nameDescriptor = validator.getConstraintsForClass( Woman.class ).getConstraintsForProperty("name");
-        Set<ConstraintDescriptor<?>> constraints = nameDescriptor.findConstraints().lookingAt(Scope.HIERARCHY).getConstraintDescriptors();
+        PropertyDescriptor nameDescriptor =
+            validator.getConstraintsForClass(Woman.class).getConstraintsForProperty("name");
+        Set<ConstraintDescriptor<?>> constraints =
+            nameDescriptor.findConstraints().lookingAt(Scope.HIERARCHY).getConstraintDescriptors();
         Assert.assertEquals("Incorrect number of descriptors", 1, constraints.size());
-        
+
         constraints = nameDescriptor.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
         Assert.assertEquals("Incorrect number of descriptors", 0, constraints.size());
     }
-    
+
     public static class Form {
         @NotNull
         public String name;
     }
-    
+
     public static class Account {
-        @Password(groups={Group1.class})
+        @Password(groups = { Group1.class })
         public String password;
     }
-    
-    @NotNull(groups={})
+
+    @NotNull(groups = {})
     @Constraint(validatedBy = {})
     @Documented
-    @Target({ METHOD, FIELD, TYPE })
+    @Target( { METHOD, FIELD, TYPE })
     @Retention(RUNTIME)
     public static @interface Password {
         String message() default "Invalid password";
-        Class<?>[] groups() default { };
+
+        Class<?>[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static interface Group1 {
     }
-    
-    
+
     public static class Woman implements Person {
-        
+
         private String name;
 
         public String getName() {
             return this.name;
         }
-        
+
         public void setName(String name) {
             this.name = name;
         }
     }
-    
+
     public static interface Person {
         @NotNull
         String getName();
     }
-    
+
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BootstrapTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BootstrapTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BootstrapTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/BootstrapTest.java Tue Sep 14 02:43:58 2010
@@ -18,40 +18,49 @@
  */
 package org.apache.bval.jsr303;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.apache.bval.constraints.NotNullValidator;
-import org.apache.bval.jsr303.example.Customer;
-
-import javax.validation.*;
-import javax.validation.bootstrap.ProviderSpecificBootstrap;
-import javax.validation.spi.ValidationProvider;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import java.util.Set;
 
+import javax.validation.Configuration;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import javax.validation.ValidationProviderResolver;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.bootstrap.ProviderSpecificBootstrap;
+import javax.validation.spi.ValidationProvider;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.bval.constraints.NotNullValidator;
+import org.apache.bval.jsr303.example.Customer;
+
 /**
  * Description: <br/>
  */
 public class BootstrapTest extends TestCase {
     public void testDirectBootstrap() {
-        Validator validator =
-                ApacheValidatorFactory.getDefault().getValidator();
+        Validator validator = ApacheValidatorFactory.getDefault().getValidator();
         Assert.assertNotNull(validator);
-        Assert.assertTrue(ApacheValidatorFactory.getDefault() ==
-                ApacheValidatorFactory.getDefault());
+        Assert.assertTrue(ApacheValidatorFactory.getDefault() == ApacheValidatorFactory.getDefault());
     }
 
     public void testEverydayBootstrap() {
-        ApacheValidatorFactory factory =
-                (ApacheValidatorFactory) Validation.buildDefaultValidatorFactory();
+        ApacheValidatorFactory factory = (ApacheValidatorFactory) Validation.buildDefaultValidatorFactory();
         Validator validator = factory.getValidator();
         Assert.assertNotNull(validator);
 
-        // each call to Validation.getValidationBuilder() returns a new builder with new state
-        ApacheValidatorFactory factory2 =
-                (ApacheValidatorFactory) Validation.buildDefaultValidatorFactory();
+        // each call to Validation.getValidationBuilder() returns a new builder
+        // with new state
+        ApacheValidatorFactory factory2 = (ApacheValidatorFactory) Validation.buildDefaultValidatorFactory();
         Assert.assertTrue(factory2 != factory);
         Assert.assertTrue(factory2.getMessageInterpolator() != factory.getMessageInterpolator());
 
@@ -72,8 +81,8 @@ public class BootstrapTest extends TestC
     }
 
     /**
-     * some tests based on RI tested behaviors to ensure our 
-     * implementation works as the reference implementation
+     * some tests based on RI tested behaviors to ensure our implementation
+     * works as the reference implementation
      */
 
     public void testCustomConstraintFactory() {
@@ -91,37 +100,34 @@ public class BootstrapTest extends TestC
         Assert.assertFalse(ConstraintViolations.isEmpty());
 
         builder = Validation.byDefaultProvider().configure();
-        builder.constraintValidatorFactory(
-                new ConstraintValidatorFactory() {
-                    public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
-                        if (key == NotNullValidator.class) {
-                            return (T) new BadlyBehavedNotNullValidator();
-                        }
-                        return new DefaultConstraintValidatorFactory().getInstance(key);
-                    }
+        builder.constraintValidatorFactory(new ConstraintValidatorFactory() {
+            public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
+                if (key == NotNullValidator.class) {
+                    @SuppressWarnings("unchecked")
+                    final T result = (T) new BadlyBehavedNotNullValidator();
+                    return result;
                 }
-        );
+                return new DefaultConstraintValidatorFactory().getInstance(key);
+            }
+        });
         factory = builder.buildValidatorFactory();
         validator = factory.getValidator();
         Set<ConstraintViolation<Customer>> ConstraintViolations2 = validator.validate(customer);
-        Assert.assertTrue("Wrong number of constraints",
-                ConstraintViolations.size() > ConstraintViolations2.size());
+        Assert.assertTrue("Wrong number of constraints", ConstraintViolations.size() > ConstraintViolations2.size());
     }
 
     public void testCustomResolverAndType() {
         ValidationProviderResolver resolver = new ValidationProviderResolver() {
 
             public List<ValidationProvider<?>> getValidationProviders() {
-                List<ValidationProvider<?>> list = new ArrayList(1);
+                List<ValidationProvider<?>> list = new ArrayList<ValidationProvider<?>>(1);
                 list.add(new ApacheValidationProvider());
                 return list;
             }
         };
 
-        ApacheValidatorConfiguration builder = Validation
-                .byProvider(ApacheValidationProvider.class)
-                .providerResolver(resolver)
-                .configure();
+        ApacheValidatorConfiguration builder =
+            Validation.byProvider(ApacheValidationProvider.class).providerResolver(resolver).configure();
         assertDefaultBuilderAndFactory(builder);
     }
 
@@ -129,20 +135,15 @@ public class BootstrapTest extends TestC
         ValidationProviderResolver resolver = new ValidationProviderResolver() {
 
             public List<ValidationProvider<?>> getValidationProviders() {
-                List list = new ArrayList();
-                list.add(new ApacheValidationProvider());
-                return list;
+                return Collections.<ValidationProvider<?>> singletonList(new ApacheValidationProvider());
             }
         };
 
-        Configuration<?> builder = Validation
-                .byDefaultProvider()
-                .providerResolver(resolver)
-                .configure();
+        Configuration<?> builder = Validation.byDefaultProvider().providerResolver(resolver).configure();
         assertDefaultBuilderAndFactory(builder);
     }
 
-    private void assertDefaultBuilderAndFactory(Configuration builder) {
+    private void assertDefaultBuilderAndFactory(Configuration<?> builder) {
         Assert.assertNotNull(builder);
         Assert.assertTrue(builder instanceof ConfigurationImpl);
 
@@ -155,26 +156,22 @@ public class BootstrapTest extends TestC
         ValidationProviderResolver resolver = new ValidationProviderResolver() {
 
             public List<ValidationProvider<?>> getValidationProviders() {
-                return new ArrayList();
+                return Collections.emptyList();
             }
         };
 
         ProviderSpecificBootstrap<ApacheValidatorConfiguration> type =
-                Validation.byProvider(ApacheValidationProvider.class);
+            Validation.byProvider(ApacheValidationProvider.class);
 
         final ProviderSpecificBootstrap<ApacheValidatorConfiguration> specializedBuilderFactory =
-                type.providerResolver(resolver);
+            type.providerResolver(resolver);
 
         try {
             specializedBuilderFactory.configure();
             Assert.fail();
-        }
-        catch (ValidationException e) {
-            Assert.assertTrue(
-                    "Wrong error message",
-                    e.getMessage().contains("provider") && 
-                    e.getMessage().contains("org.apache.bval.jsr303.ApacheValidationProvider")
-            );
+        } catch (ValidationException e) {
+            Assert.assertTrue("Wrong error message", e.getMessage().contains("provider")
+                && e.getMessage().contains("org.apache.bval.jsr303.ApacheValidationProvider"));
         }
     }
 

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/CircularReferencesTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/CircularReferencesTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/CircularReferencesTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/CircularReferencesTest.java Tue Sep 14 02:43:58 2010
@@ -34,15 +34,33 @@ import java.util.Set;
  * @author Carlos Vara
  */
 public class CircularReferencesTest extends TestCase {
-    
     static ValidatorFactory factory;
 
     static {
         factory = Validation.buildDefaultValidatorFactory();
-        ((DefaultMessageInterpolator)factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
     }
 
-    private Validator getValidator() {
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
 
@@ -51,15 +69,12 @@ public class CircularReferencesTest exte
      * dependency.
      */
     public void testAutoreferringBean() {
-        
-        Validator validator = getValidator();
-        
         Person p1 = new Person();
         p1.name = "too-long-name";
         p1.sibling = p1;
-        
+
         Set<ConstraintViolation<Person>> violations = validator.validate(p1);
-        
+
         Assert.assertEquals("Only 1 violation should be reported", 1, violations.size());
         ConstraintViolation<Person> violation = violations.iterator().next();
         Assert.assertEquals("Incorrect violation path", "name", violation.getPropertyPath().toString());
@@ -70,37 +85,32 @@ public class CircularReferencesTest exte
      * paths inside the bean graph.
      */
     public void testNonCircularArrayOfSameBean() {
-        
-        Validator validator = getValidator();
-        
         Boss boss = new Boss();
         Person p1 = new Person();
         p1.name = "too-long-name";
-        
-        boss.employees = new Person[]{ p1, p1, p1, p1 };
-        
+
+        boss.employees = new Person[] { p1, p1, p1, p1 };
+
         Set<ConstraintViolation<Boss>> violations = validator.validate(boss);
-        
+
         Assert.assertEquals("A total of 4 violations should be reported", 4, violations.size());
-        
     }
-    
-    
+
     public static class Person {
-        
+
         @Valid
         public Person sibling;
-        
-        @Size(max=10)
+
+        @Size(max = 10)
         public String name;
-        
+
     }
-    
+
     public static class Boss {
-        
+
         @Valid
         public Person[] employees;
-        
+
     }
-    
+
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ComposedConstraintsTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ComposedConstraintsTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ComposedConstraintsTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ComposedConstraintsTest.java Tue Sep 14 02:43:58 2010
@@ -18,11 +18,8 @@
  */
 package org.apache.bval.jsr303;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.apache.bval.jsr303.example.CompanyAddress;
-import org.apache.bval.jsr303.example.FrenchAddress;
-import org.apache.bval.jsr303.util.TestUtils;
+import java.util.Locale;
+import java.util.Set;
 
 import javax.validation.ConstraintViolation;
 import javax.validation.Validation;
@@ -31,7 +28,13 @@ import javax.validation.ValidatorFactory
 import javax.validation.constraints.Size;
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.ElementDescriptor;
-import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.bval.jsr303.example.CompanyAddress;
+import org.apache.bval.jsr303.example.FrenchAddress;
+import org.apache.bval.jsr303.util.TestUtils;
 
 /**
  * Description: <br/>
@@ -41,15 +44,38 @@ public class ComposedConstraintsTest ext
 
     static {
         factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
+        return factory.getValidator();
     }
 
     public void testMetaDataAPI_ComposedConstraints() {
-        Validator addressValidator = factory.getValidator();
         ElementDescriptor ed =
-              addressValidator.getConstraintsForClass(FrenchAddress.class)
+              validator.getConstraintsForClass(FrenchAddress.class)
                     .getConstraintsForProperty("zipCode");
         Assert.assertEquals(1, ed.getConstraintDescriptors().size());
-        for (ConstraintDescriptor cd : ed.getConstraintDescriptors()) {
+        for (ConstraintDescriptor<?> cd : ed.getConstraintDescriptors()) {
             Assert.assertTrue(cd.isReportAsSingleViolation());
             Assert.assertEquals(3, cd.getComposingConstraints().size());
             Assert.assertTrue("no composing constraints found!!",
@@ -58,51 +84,48 @@ public class ComposedConstraintsTest ext
         }
     }
 
-    public void processConstraintDescriptor(ConstraintDescriptor cd) {
+    public void processConstraintDescriptor(ConstraintDescriptor<?> cd) {
         //Size.class is understood by the tool
         if (cd.getAnnotation().annotationType().equals(Size.class)) {
-            Size m = (Size) cd.getAnnotation();
-//            System.out.println("size.max = " + m.max());  //read and use the metadata
+            Size m = (Size) cd.getAnnotation();//what for?
         }
-        for (Object composingCd : cd.getComposingConstraints()) {
-            processConstraintDescriptor((ConstraintDescriptor) composingCd);
+        for (ConstraintDescriptor<?> composingCd : cd.getComposingConstraints()) {
             //check composing constraints recursively
+            processConstraintDescriptor(composingCd);
         }
     }
 
     public void testValidateComposed() {
         FrenchAddress adr = new FrenchAddress();
-        Validator val = factory.getValidator();
-        Set<ConstraintViolation<FrenchAddress>> findings = val.validate(adr);
+        Set<ConstraintViolation<FrenchAddress>> findings = validator.validate(adr);
         Assert.assertEquals(1, findings.size()); // with @ReportAsSingleConstraintViolation
 
         ConstraintViolation<FrenchAddress> finding = findings.iterator().next();
         Assert.assertEquals("Wrong zipcode", finding.getMessage());
 
         adr.setZipCode("1234567");
-        findings = val.validate(adr);
+        findings = validator.validate(adr);
         Assert.assertEquals(0, findings.size());
 
         adr.setZipCode("1234567234567");
-        findings = val.validate(adr);
+        findings = validator.validate(adr);
         Assert.assertTrue(findings.size() > 0); // too long
     }
 
     public void testOverridesAttributeConstraintIndex() {
         CompanyAddress adr = new CompanyAddress("invalid-string");
-        Validator val = factory.getValidator();
-        Set<ConstraintViolation<CompanyAddress>> findings = val.validate(adr);
+        Set<ConstraintViolation<CompanyAddress>> findings = validator.validate(adr);
         assertEquals(2, findings.size()); // without @ReportAsSingleConstraintViolation
         assertNotNull(TestUtils.getViolationWithMessage(findings, "Not COMPANY"));
         assertNotNull(TestUtils.getViolationWithMessage(findings, "Not an email"));
 
         adr =  new CompanyAddress("JOHN_DO@WEB.DE");
-        findings = val.validate(adr);
+        findings = validator.validate(adr);
         assertEquals(1, findings.size());
         assertNotNull(TestUtils.getViolationWithMessage(findings, "Not COMPANY"));
 
         adr =  new CompanyAddress("JOHN_DO@COMPANY.DE");
-        findings = val.validate(adr);
+        findings = validator.validate(adr);
         Assert.assertTrue(findings.isEmpty());
     }
 

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintCompositionTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintCompositionTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintCompositionTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintCompositionTest.java Tue Sep 14 02:43:58 2010
@@ -19,14 +19,11 @@
 
 package org.apache.bval.jsr303;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
-import javax.validation.*;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Pattern;
-import javax.validation.constraints.Size;
-import javax.validation.metadata.ConstraintDescriptor;
 import java.lang.annotation.Annotation;
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
@@ -34,8 +31,21 @@ import java.lang.annotation.Target;
 import java.util.Locale;
 import java.util.Set;
 
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import javax.validation.Constraint;
+import javax.validation.ConstraintViolation;
+import javax.validation.OverridesAttribute;
+import javax.validation.Payload;
+import javax.validation.ReportAsSingleViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import javax.validation.metadata.ConstraintDescriptor;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
 
 /**
  * Checks that groups are correctly inherited from the root constraint to its
@@ -44,7 +54,6 @@ import static java.lang.annotation.Reten
  * @author Carlos Vara
  */
 public class ConstraintCompositionTest extends TestCase {
-
     static ValidatorFactory factory;
 
     static {
@@ -52,36 +61,53 @@ public class ConstraintCompositionTest e
         ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
     }
 
-    private Validator getValidator() {
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
-    
+
     /**
      * Check correct group inheritance on constraint composition on a 1 level
      * hierarchy.
      */
     public void test1LevelInheritance() {
-        Validator validator = getValidator();
         Set<ConstraintViolation<Person>> violations = validator.validate(new Person());
-        
+
         Assert.assertEquals("Wrong number of violations detected", 1, violations.size());
         String msg = violations.iterator().next().getMessage();
         Assert.assertEquals("Incorrect violation message", "A person needs a non null name", msg);
-        
+
         violations = validator.validate(new Person(), Group1.class);
         Assert.assertEquals("Wrong number of violations detected", 0, violations.size());
     }
-    
+
     /**
      * Check correct group inheritance on constraint composition on a 2 level
      * hierarchy.
      */
     public void test2LevelInheritance() {
-        Validator validator = getValidator();
         Set<ConstraintViolation<Man>> violations = validator.validate(new Man());
-        
+
         Assert.assertEquals("Wrong number of violations detected", 0, violations.size());
-        
+
         violations = validator.validate(new Man(), Group1.class);
         Assert.assertEquals("Wrong number of violations detected", 1, violations.size());
         String msg = violations.iterator().next().getMessage();
@@ -93,10 +119,10 @@ public class ConstraintCompositionTest e
      * correctly set to the inherited ones.
      */
     public void testAnnotationGroupsAreInherited() {
-        Validator validator = getValidator();
-        
         // Check that the groups() value is right when querying the metadata
-        ConstraintDescriptor<?> manNameDesc = getValidator().getConstraintsForClass(Man.class).getConstraintsForProperty("name").getConstraintDescriptors().iterator().next();
+        ConstraintDescriptor<?> manNameDesc =
+            validator.getConstraintsForClass(Man.class).getConstraintsForProperty("name").getConstraintDescriptors()
+                .iterator().next();
         ConstraintDescriptor<?> personNameDesc = manNameDesc.getComposingConstraints().iterator().next();
         ConstraintDescriptor<?> notNullDesc = personNameDesc.getComposingConstraints().iterator().next();
         Assert.assertEquals("There should only be 1 group", 1, manNameDesc.getGroups().size());
@@ -105,23 +131,24 @@ public class ConstraintCompositionTest e
         Assert.assertTrue("Group1 should be present", personNameDesc.getGroups().contains(Group1.class));
         Assert.assertEquals("There should only be 1 group", 1, personNameDesc.getGroups().size());
         Assert.assertTrue("Group1 should be present", notNullDesc.getGroups().contains(Group1.class));
-        
-        // Check that the groups() value is right when accessing it from an error
+
+        // Check that the groups() value is right when accessing it from an
+        // error
         Set<ConstraintViolation<Man>> violations = validator.validate(new Man(), Group1.class);
         Set<Class<?>> notNullGroups = violations.iterator().next().getConstraintDescriptor().getGroups();
         Assert.assertEquals("There should only be 1 group", 1, notNullGroups.size());
         Assert.assertTrue("Group1 should be the only group", notNullGroups.contains(Group1.class));
     }
-    
+
     /**
      * Checks that the payload() value of the constraint annotations are
      * correctly set to the inherited ones.
      */
     public void testAnnotationPayloadsAreInherited() {
-        Validator validator = getValidator();
-        
         // Check that the payload() value is right when querying the metadata
-        ConstraintDescriptor<?> manNameDesc = getValidator().getConstraintsForClass(Man.class).getConstraintsForProperty("name").getConstraintDescriptors().iterator().next();
+        ConstraintDescriptor<?> manNameDesc =
+            validator.getConstraintsForClass(Man.class).getConstraintsForProperty("name").getConstraintDescriptors()
+                .iterator().next();
         ConstraintDescriptor<?> personNameDesc = manNameDesc.getComposingConstraints().iterator().next();
         ConstraintDescriptor<?> notNullDesc = personNameDesc.getComposingConstraints().iterator().next();
         Assert.assertEquals("There should only be 1 payload class", 1, manNameDesc.getPayload().size());
@@ -130,10 +157,12 @@ public class ConstraintCompositionTest e
         Assert.assertTrue("Payload1 should be present", personNameDesc.getPayload().contains(Payload1.class));
         Assert.assertEquals("There should only be 1 payload class", 1, personNameDesc.getPayload().size());
         Assert.assertTrue("Payload1 should be present", notNullDesc.getPayload().contains(Payload1.class));
-        
-        // Check that the payload() value is right when accessing it from an error
+
+        // Check that the payload() value is right when accessing it from an
+        // error
         Set<ConstraintViolation<Man>> violations = validator.validate(new Man(), Group1.class);
-        Set<Class<? extends Payload>> notNullPayload = violations.iterator().next().getConstraintDescriptor().getPayload();
+        Set<Class<? extends Payload>> notNullPayload =
+            violations.iterator().next().getConstraintDescriptor().getPayload();
         Assert.assertEquals("There should only be 1 payload class", 1, notNullPayload.size());
         Assert.assertTrue("Payload1 should be the only payload", notNullPayload.contains(Payload1.class));
     }
@@ -143,23 +172,21 @@ public class ConstraintCompositionTest e
      * applying works.
      */
     public void testIndexedOverridesAttributes() {
-        Validator validator = getValidator();
-        
         Person p = new Person();
         p.name = "valid";
-        
+
         // With a valid id, no errors expected
         p.id = "1234";
         Set<ConstraintViolation<Person>> constraintViolations = validator.validate(p);
         Assert.assertTrue("No violations should be reported on valid id", constraintViolations.isEmpty());
-        
+
         // With a short id, only 1 error expected
         p.id = "1";
         constraintViolations = validator.validate(p);
         Assert.assertEquals("Only 1 violation expected", 1, constraintViolations.size());
         ConstraintViolation<Person> violation = constraintViolations.iterator().next();
         Assert.assertEquals("Wrong violation", "Id is too short", violation.getMessage());
-        
+
         // With a long id, only 1 error expected
         p.id = "loooooong id";
         constraintViolations = validator.validate(p);
@@ -173,101 +200,107 @@ public class ConstraintCompositionTest e
      * {@link ReportAsSingleViolation}.
      */
     public void testReportAsAsingleViolation() {
-        Validator validator = getValidator();
-        
         Code c = new Code();
         c.code = "very invalid code";
         Set<ConstraintViolation<Code>> constraintViolations = validator.validate(c);
-        
+
         // Only 1 error expected
         Assert.assertEquals("Only 1 violation expected", 1, constraintViolations.size());
         ConstraintViolation<Code> violation = constraintViolations.iterator().next();
         Assert.assertEquals("Wrong violation message", "Invalid code", violation.getMessage());
-        Assert.assertEquals("Wrong violation type", ElevenDigitsCode.class, ((Annotation)violation.getConstraintDescriptor().getAnnotation()).annotationType());
-        
+        Assert.assertEquals("Wrong violation type", ElevenDigitsCode.class, ((Annotation) violation
+            .getConstraintDescriptor().getAnnotation()).annotationType());
     }
-    
+
     public static class Person {
         @PersonName
         String name;
-        
+
         @PersonId
         String id;
     }
-    
+
     public static class Man {
-        @ManName(groups={Group1.class},payload={Payload1.class})
+        @ManName(groups = { Group1.class }, payload = { Payload1.class })
         String name;
     }
-    
+
     public static class Code {
         @ElevenDigitsCode
         String code;
     }
-    
-    @NotNull(message="A person needs a non null name", groups={Group1.class}, payload={})
+
+    @NotNull(message = "A person needs a non null name", groups = { Group1.class }, payload = {})
     @Constraint(validatedBy = {})
     @Documented
-    @Target({ METHOD, FIELD, TYPE })
+    @Target( { METHOD, FIELD, TYPE })
     @Retention(RUNTIME)
     public static @interface PersonName {
         String message() default "Wrong person name";
-        Class<?>[] groups() default { };
+
+        Class<?>[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
-    @PersonName(groups={Group2.class},payload={Payload1.class,Payload2.class})
+
+    @PersonName(groups = { Group2.class }, payload = { Payload1.class, Payload2.class })
     @Constraint(validatedBy = {})
     @Documented
-    @Target({ METHOD, FIELD, TYPE })
+    @Target( { METHOD, FIELD, TYPE })
     @Retention(RUNTIME)
     public static @interface ManName {
         String message() default "Wrong man name";
-        Class<?>[] groups() default { };
+
+        Class<?>[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
-    
-    @Size.List({ @Size(min=3, max=3, message="Id is too short"), @Size(min=5,max=5, message="Id is too long") })
+
+    @Size.List( { @Size(min = 3, max = 3, message = "Id is too short"),
+        @Size(min = 5, max = 5, message = "Id is too long") })
     @Constraint(validatedBy = {})
     @Documented
-    @Target({ METHOD, FIELD, TYPE })
+    @Target( { METHOD, FIELD, TYPE })
     @Retention(RUNTIME)
     public static @interface PersonId {
         String message() default "Wrong person id";
-        Class<?>[] groups() default { };
+
+        Class<?>[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
-        
-        @OverridesAttribute(constraint=Size.class,constraintIndex=0,name="max")
+
+        @OverridesAttribute(constraint = Size.class, constraintIndex = 0, name = "max")
         int maxSize() default 1000;
-        
-        @OverridesAttribute(constraint=Size.class,constraintIndex=1,name="min")
+
+        @OverridesAttribute(constraint = Size.class, constraintIndex = 1, name = "min")
         int minSize() default 0;
     }
-    
-    @Size(min=11, max=11)
-    @Pattern(regexp="\\d*")
+
+    @Size(min = 11, max = 11)
+    @Pattern(regexp = "\\d*")
     @Constraint(validatedBy = {})
     @ReportAsSingleViolation
     @Documented
-    @Target({ METHOD, FIELD, TYPE })
+    @Target( { METHOD, FIELD, TYPE })
     @Retention(RUNTIME)
     public static @interface ElevenDigitsCode {
         String message() default "Invalid code";
-        Class<?>[] groups() default { };
+
+        Class<?>[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static interface Group1 {
     }
-    
+
     public static interface Group2 {
     }
-    
+
     public static class Payload1 implements Payload {
     }
-    
+
     public static class Payload2 implements Payload {
     }
-    
+
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java Tue Sep 14 02:43:58 2010
@@ -18,23 +18,31 @@
  */
 package org.apache.bval.jsr303;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.apache.bval.constraints.NotNullValidator;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
-import javax.validation.*;
-import javax.validation.constraints.Min;
-import javax.validation.metadata.BeanDescriptor;
-import javax.validation.metadata.ConstraintDescriptor;
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 import java.util.Locale;
 import java.util.Set;
 
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import javax.validation.Constraint;
+import javax.validation.ConstraintDefinitionException;
+import javax.validation.Payload;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.constraints.Min;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
 
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.bval.constraints.NotNullValidator;
 
 /**
  * Checks the correct parsing of constraint definitions.
@@ -42,7 +50,6 @@ import static java.lang.annotation.Reten
  * @author Carlos Vara
  */
 public class ConstraintDefinitionsTest extends TestCase {
-    
     static ValidatorFactory factory;
 
     static {
@@ -50,23 +57,42 @@ public class ConstraintDefinitionsTest e
         ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
     }
 
-    private Validator getValidator() {
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
-    
-    
+
     /**
      * Checks the correct parsing of a constraint with an array of constraints
      * as attributes.
      */
     public void testCustomAttributes() {
-        Validator validator = getValidator();
         BeanDescriptor constraints = validator.getConstraintsForClass(Person.class);
-        Set<ConstraintDescriptor<?>> ageConstraints = constraints.getConstraintsForProperty("age").getConstraintDescriptors();
-        
+        Set<ConstraintDescriptor<?>> ageConstraints =
+            constraints.getConstraintsForProperty("age").getConstraintDescriptors();
+
         Assert.assertEquals("There should be 2 constraints in 'age'", ageConstraints.size(), 2);
-        for ( ConstraintDescriptor<?> cd : ageConstraints ) {
-            Assert.assertEquals("Annotation should be @Min", cd.getAnnotation().annotationType().getName(), Min.class.getName());
+        for (ConstraintDescriptor<?> cd : ageConstraints) {
+            Assert.assertEquals("Annotation should be @Min", cd.getAnnotation().annotationType().getName(), Min.class
+                .getName());
         }
     }
 
@@ -76,7 +102,7 @@ public class ConstraintDefinitionsTest e
      */
     public void testNoGroupsConstraint() {
         try {
-            getValidator().validate(new NoGroups());
+            validator.validate(new NoGroups());
             fail("No exception thrown when parsing a constraint definition with no groups() method");
         } catch (ConstraintDefinitionException e) {
             // correct
@@ -90,7 +116,7 @@ public class ConstraintDefinitionsTest e
      */
     public void testInvalidDefaultGroupsConstraint() {
         try {
-            getValidator().validate(new InvalidGroups());
+            validator.validate(new InvalidGroups());
             fail("No exception thrown when parsing a constraint definition with a groups() method does not return Class[]");
         } catch (ConstraintDefinitionException e) {
             // correct
@@ -103,13 +129,13 @@ public class ConstraintDefinitionsTest e
      */
     public void testNoPayloadConstraint() {
         try {
-            getValidator().validate(new NoPayload());
+            validator.validate(new NoPayload());
             fail("No exception thrown when parsing a constraint definition with no payload() method");
         } catch (ConstraintDefinitionException e) {
             // correct
         }
     }
-    
+
     /**
      * Checks that a {@link ConstraintDefinitionException} is thrown when
      * parsing a constraint definition with an invalid <code>payload()</code>
@@ -117,7 +143,7 @@ public class ConstraintDefinitionsTest e
      */
     public void testInvalidDefaultPayloadConstraint() {
         try {
-            getValidator().validate(new InvalidPayload());
+            validator.validate(new InvalidPayload());
             fail("No exception thrown when parsing a constraint definition with a payload() method does not return an empty array");
         } catch (ConstraintDefinitionException e) {
             // correct
@@ -130,13 +156,13 @@ public class ConstraintDefinitionsTest e
      */
     public void testNoMessageConstraint() {
         try {
-            getValidator().validate(new NoMessage());
+            validator.validate(new NoMessage());
             fail("No exception thrown when parsing a constraint definition with no payload() method");
         } catch (ConstraintDefinitionException e) {
             // correct
         }
     }
-    
+
     /**
      * Checks that a {@link ConstraintDefinitionException} is thrown when
      * parsing a constraint definition with an invalid <code>message()</code>
@@ -144,7 +170,7 @@ public class ConstraintDefinitionsTest e
      */
     public void testInvalidDefaultMessageConstraint() {
         try {
-            getValidator().validate(new InvalidMessage());
+            validator.validate(new InvalidMessage());
             fail("No exception thrown when parsing a constraint definition with a message() method does not return a String");
         } catch (ConstraintDefinitionException e) {
             // correct
@@ -157,130 +183,140 @@ public class ConstraintDefinitionsTest e
      */
     public void testInvalidAttributeConstraint() {
         try {
-            getValidator().validate(new InvalidAttribute());
+            validator.validate(new InvalidAttribute());
             fail("No exception thrown when parsing a constraint definition with a method starting with 'valid'");
         } catch (ConstraintDefinitionException e) {
             // correct
         }
     }
-    
+
     public static class Person {
-        @MinList({
-            @Min(value=20),
-            @Min(value=30)
-        })
+        @MinList( { @Min(value = 20), @Min(value = 30) })
         public Integer age;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
     public static @interface MinList {
         Min[] value();
     }
-    
+
     public static class NoGroups {
         @NoGroupsConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface NoGroupsConstraint {
         String message() default "def msg";
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class InvalidGroups {
         @InvalidGroupsConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface InvalidGroupsConstraint {
         String message() default "def msg";
+
         String[] groups() default { "Group1" };
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class NoPayload {
         @NoPayloadConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface NoPayloadConstraint {
         String message() default "def msg";
+
         String[] groups() default {};
     }
-    
+
     public static class InvalidPayload {
         @InvalidPayloadConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface InvalidPayloadConstraint {
         String message() default "def msg";
+
         String[] groups() default {};
-        Class<? extends Payload>[] payload() default {Payload1.class};
+
+        Class<? extends Payload>[] payload() default { Payload1.class };
+
         public static class Payload1 implements Payload {
         }
     }
-    
+
     public static class NoMessage {
         @NoMessageConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface NoMessageConstraint {
         String[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class InvalidMessage {
-        @InvalidMessageConstraint(message=2)
+        @InvalidMessageConstraint(message = 2)
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface InvalidMessageConstraint {
         int message();
+
         String[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class InvalidAttribute {
         @InvalidAttributeConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface InvalidAttributeConstraint {
         String message() default "def msg";
+
         String[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
+
         String validValue() default "1";
     }
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java Tue Sep 14 02:43:58 2010
@@ -62,7 +62,7 @@ public class DefaultMessageInterpolatorT
 
             public ConstraintDescriptor<?> getConstraintDescriptor() {
                 return (ConstraintDescriptor<?>) gvalidator.getConstraintsForClass(PreferredGuest.class)
-                    .getConstraintsForProperty("guestCreditCardNumber").getConstraintDescriptors().toArray()[0];
+                    .getConstraintsForProperty("guestCreditCardNumber").getConstraintDescriptors().iterator().next();
             }
 
             public Object getValidatedValue() {
@@ -74,8 +74,8 @@ public class DefaultMessageInterpolatorT
 
         ctx = new MessageInterpolator.Context() {
             public ConstraintDescriptor<?> getConstraintDescriptor() {
-                return (ConstraintDescriptor) gvalidator.getConstraintsForClass(Author.class)
-                    .getConstraintsForProperty("lastName").getConstraintDescriptors().toArray()[0];
+                return gvalidator.getConstraintsForClass(Author.class).getConstraintsForProperty("lastName")
+                    .getConstraintDescriptors().iterator().next();
             }
 
             public Object getValidatedValue() {
@@ -101,7 +101,7 @@ public class DefaultMessageInterpolatorT
 
             public ConstraintDescriptor<?> getConstraintDescriptor() {
                 return (ConstraintDescriptor<?>) validator.getConstraintsForClass(Person.class)
-                    .getConstraintsForProperty("idNumber").getConstraintDescriptors().toArray()[0];
+                    .getConstraintsForProperty("idNumber").getConstraintDescriptors().iterator().next();
             }
 
             public Object getValidatedValue() {
@@ -118,7 +118,7 @@ public class DefaultMessageInterpolatorT
 
             public ConstraintDescriptor<?> getConstraintDescriptor() {
                 return (ConstraintDescriptor<?>) validator.getConstraintsForClass(Person.class)
-                    .getConstraintsForProperty("otherId").getConstraintDescriptors().toArray()[0];
+                    .getConstraintsForProperty("otherId").getConstraintDescriptors().iterator().next();
             }
 
             public Object getValidatedValue() {

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java Tue Sep 14 02:43:58 2010
@@ -36,7 +36,6 @@ import java.util.Locale;
  * @author Carlos Vara
  */
 public class ExceptionsContractTest extends TestCase {
-
     static ValidatorFactory factory;
 
     static {
@@ -44,7 +43,26 @@ public class ExceptionsContractTest exte
         ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
     }
 
-    private Validator getValidator() {
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
 
@@ -53,7 +71,6 @@ public class ExceptionsContractTest exte
      * getter throws an exception.
      */
     public void testExceptionThrowingBean() {
-        Validator validator = getValidator();
         try {
             validator.validate(new ExceptionThrowingBean());
             Assert.fail("No exception thrown when validating a bean whose getter throws a RTE");
@@ -67,7 +84,6 @@ public class ExceptionsContractTest exte
      * <code>null</code> as group array.
      */
     public void testValidateNullGroup() {
-        Validator validator = getValidator();
         try {
             Class<?>[] groups = null;
             validator.validate(new String(), groups);
@@ -82,7 +98,6 @@ public class ExceptionsContractTest exte
      * invalid property name.
      */
     public void testValidateInvalidPropertyName() {
-        Validator validator = getValidator();
 
         // Null propertyName
         try {
@@ -112,7 +127,6 @@ public class ExceptionsContractTest exte
      * validate a property on a null object.
      */
     public void testValidatePropertyOnNullBean() {
-        Validator validator = getValidator();
         try {
             validator.validateProperty(null, "class");
         } catch (IllegalArgumentException e) {
@@ -126,7 +140,6 @@ public class ExceptionsContractTest exte
      * {@link Validator#validateProperty(Object, String, Class...)} call.
      */
     public void testValidatePropertyNullGroup() {
-        Validator validator = getValidator();
         try {
             Class<?>[] groups = null;
             validator.validateProperty(new Person(), "name", groups);
@@ -142,7 +155,6 @@ public class ExceptionsContractTest exte
      * <code>null</code> class.
      */
     public void testValidateValueOnNullClass() {
-        Validator validator = getValidator();
         try {
             validator.validateValue(null, "class", Object.class);
             Assert.fail("No exception thrown when passing null as group array");
@@ -157,8 +169,6 @@ public class ExceptionsContractTest exte
      * {@link Validator#validateValue(Class, String, Object, Class...)}.
      */
     public void testValidateValueInvalidPropertyName() {
-        Validator validator = getValidator();
-
         // Null propertyName
         try {
             validator.validateValue(Person.class, null, "John");
@@ -187,7 +197,6 @@ public class ExceptionsContractTest exte
      * <code>null</code> group array.
      */
     public void testValidateValueNullGroup() {
-        Validator validator = getValidator();
         try {
             Class<?>[] groups = null;
             validator.validateValue(Person.class, "name", "John", groups);
@@ -203,16 +212,15 @@ public class ExceptionsContractTest exte
      * property name.
      */
     public void testGetConstraintsForInvalidProperty() {
-        Validator validator = getValidator();
         BeanDescriptor personDescriptor = validator.getConstraintsForClass(Person.class);
-        
+
         try {
             personDescriptor.getConstraintsForProperty(null);
             fail("No exception thrown when calling getConstraintsForProperty with null property");
         } catch (IllegalArgumentException e) {
             // Correct
         }
-        
+
         try {
             personDescriptor.getConstraintsForProperty("");
             fail("No exception thrown when calling getConstraintsForProperty with empty property");
@@ -220,7 +228,6 @@ public class ExceptionsContractTest exte
             // Correct
         }
     }
-    
 
     public static class ExceptionThrowingBean {
 
@@ -232,10 +239,10 @@ public class ExceptionsContractTest exte
     }
 
     public static class Person {
-        
+
         @NotNull
         public String name;
-        
+
     }
 
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/FooTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/FooTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/FooTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/FooTest.java Tue Sep 14 02:43:58 2010
@@ -60,7 +60,7 @@ public class FooTest extends TestCase {
         Validator v = ApacheValidatorFactory.getDefault().getValidator();
         Set<ConstraintViolation<FooTest>> errors = v.validate(t);
         System.out.println("got errors:");
-        for (ConstraintViolation error : errors) {
+        for (ConstraintViolation<?> error : errors) {
             System.out.println(error.getPropertyPath());
         }
     }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java Tue Sep 14 02:43:58 2010
@@ -18,126 +18,171 @@
  */
 package org.apache.bval.jsr303;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.apache.bval.constraints.SizeValidatorForString;
-import org.apache.bval.jsr303.example.*;
-import org.apache.bval.jsr303.util.TestUtils;
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
 
 import javax.validation.ConstraintViolation;
 import javax.validation.UnexpectedTypeException;
+import javax.validation.Validation;
 import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
 import javax.validation.metadata.BeanDescriptor;
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.ElementDescriptor;
 import javax.validation.metadata.PropertyDescriptor;
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.bval.constraints.SizeValidatorForString;
+import org.apache.bval.jsr303.example.Address;
+import org.apache.bval.jsr303.example.Book;
+import org.apache.bval.jsr303.example.Engine;
+import org.apache.bval.jsr303.example.MaxTestEntity;
+import org.apache.bval.jsr303.example.NoValidatorTestEntity;
+import org.apache.bval.jsr303.example.Second;
+import org.apache.bval.jsr303.example.SizeTestEntity;
+import org.apache.bval.jsr303.util.TestUtils;
 
 /**
  * Description: <br/>
  */
 public class Jsr303Test extends TestCase {
-/*    static {
-        ApacheValidatorFactory.getDefault().getMetaBeanManager()
-                .addResourceLoader("org/apache/bval/example/test-beanInfos.xml");
-    }*/
-
-    /*  public void testUseCoreXmlMetaData() {
-        Validator validator = getValidator();
-
-        BusinessObject object = new BusinessObject();
-        object.setTitle("1234567834567 too long title ");
-        Set<ConstraintViolation<BusinessObject>> violations = validator.validate(object);
-        Assert.assertNotNull(violations);
-        Assert.assertTrue(!violations.isEmpty());
+    /*
+     * static { ApacheValidatorFactory.getDefault().getMetaBeanManager()
+     * .addResourceLoader("org/apache/bval/example/test-beanInfos.xml"); }
+     */
 
-        Assert.assertTrue(!validator.validateProperty(object, "title").isEmpty());
-    }*/
+    /*
+     * public void testUseCoreXmlMetaData() { Validator validator =
+     * getValidator();
+     * 
+     * BusinessObject object = new BusinessObject();
+     * object.setTitle("1234567834567 too long title ");
+     * Set<ConstraintViolation<BusinessObject>> violations =
+     * validator.validate(object); Assert.assertNotNull(violations);
+     * Assert.assertTrue(!violations.isEmpty());
+     * 
+     * Assert.assertTrue(!validator.validateProperty(object,
+     * "title").isEmpty()); }
+     */
+
+    static ValidatorFactory factory;
+
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
+        return factory.getValidator();
+    }
+
+    /**
+     * If testing a {@link Validator} implementation that does NOT
+     * cache the descriptor types, override and return false.
+     * @return boolean
+     */
+    protected boolean isDescriptorCachingImpl() {
+        return true;
+    }
 
     public void testPropertyDescriptorHasConstraints() {
-        BeanDescriptor cons = getValidator().getConstraintsForClass(Book.class);
+        BeanDescriptor cons = validator.getConstraintsForClass(Book.class);
         assertTrue(cons.getConstraintsForProperty("author").hasConstraints());
         assertTrue(cons.getConstraintsForProperty("title").hasConstraints());
         assertTrue(cons.getConstraintsForProperty("uselessField").hasConstraints());
-        // cons.getConstraintsForProperty("unconstraintField") == null without Introspector
-        // cons.getConstraintsForProperty("unconstraintField") != null with Introspector
-        assertTrue(cons.getConstraintsForProperty("unconstraintField") == null ||
-              !cons.getConstraintsForProperty("unconstraintField").hasConstraints());
+        // cons.getConstraintsForProperty("unconstraintField") == null without
+        // Introspector
+        // cons.getConstraintsForProperty("unconstraintField") != null with
+        // Introspector
+        assertTrue(cons.getConstraintsForProperty("unconstraintField") == null
+            || !cons.getConstraintsForProperty("unconstraintField").hasConstraints());
         assertNull(cons.getConstraintsForProperty("unknownField"));
     }
 
     public void testValidateValue() {
-        Validator validator = getValidator();
-        assertTrue(
-              validator.validateValue(Book.class, "subtitle", "123456789098765432").isEmpty());
+        assertTrue(validator.validateValue(Book.class, "subtitle", "123456789098765432").isEmpty());
         assertFalse(validator.validateValue(Book.class, "subtitle",
-              "123456789098765432123412345678909876543212341234564567890987654321234",
-              Second.class).isEmpty());
-        // tests for issue 22: validation of a field without any constraints 
+            "123456789098765432123412345678909876543212341234564567890987654321234", Second.class).isEmpty());
+        // tests for issue 22: validation of a field without any constraints
         assertEquals(0, validator.validateValue(Book.class, "unconstraintField", 4).size());
-        // tests for issue 22: validation of unknown field cause ValidationException
+        // tests for issue 22: validation of unknown field cause
+        // ValidationException
         try {
             validator.validateValue(Book.class, "unknownProperty", 4);
             fail("unknownProperty not detected");
         } catch (IllegalArgumentException ex) {
             // OK
-            assertEquals(
-                  "unknown property 'unknownProperty' in org.apache.bval.jsr303.example.Book",
-                  ex.getMessage());
+            assertEquals("unknown property 'unknownProperty' in org.apache.bval.jsr303.example.Book", ex.getMessage());
         }
     }
 
     public void testMetadataAPI_Book() {
-        Validator validator = getValidator();
         Assert.assertNotNull(validator.getConstraintsForClass(Book.class));
-        Assert.assertTrue(validator.getConstraintsForClass(Book.class) ==
-              validator.getConstraintsForClass(Book.class));
+        Assert.assertEquals(isDescriptorCachingImpl(), validator.getConstraintsForClass(Book.class) == validator.getConstraintsForClass(Book.class));
         BeanDescriptor bc = validator.getConstraintsForClass(Book.class);
-//        assertEquals(ElementType.TYPE, bc.getElementType());
+        // assertEquals(ElementType.TYPE, bc.getElementType());
         Assert.assertEquals(Book.class, bc.getElementClass());
-//        assertEquals(false, bc.isCascaded());
-//        assertEquals("", bc.getPropertyPath());
+        // assertEquals(false, bc.isCascaded());
+        // assertEquals("", bc.getPropertyPath());
         Assert.assertTrue(bc.getConstraintDescriptors() != null);
     }
 
     public void testMetadataAPI_Engine() {
-        Validator validator = getValidator();
-        ElementDescriptor desc = validator.getConstraintsForClass(Engine.class)
-              .getConstraintsForProperty("serialNumber");
+        ElementDescriptor desc =
+            validator.getConstraintsForClass(Engine.class).getConstraintsForProperty("serialNumber");
         assertNotNull(desc);
-//        assertEquals(ElementType.FIELD, desc.getElementType());
+        // assertEquals(ElementType.FIELD, desc.getElementType());
         Assert.assertEquals(String.class, desc.getElementClass());
     }
 
     public void testMetadataAPI_Address() {
-        Validator validator = getValidator();
-        Assert.assertFalse(validator.getConstraintsForClass(Address.class)
-              .getConstraintDescriptors().isEmpty());
-
-        Set<PropertyDescriptor> props =
-              validator.getConstraintsForClass(Address.class).getConstrainedProperties();
-        Set<String> propNames = new HashSet(props.size());
+        Assert.assertFalse(validator.getConstraintsForClass(Address.class).getConstraintDescriptors().isEmpty());
+
+        Set<PropertyDescriptor> props = validator.getConstraintsForClass(Address.class).getConstrainedProperties();
+        Set<String> propNames = new HashSet<String>(props.size());
         for (PropertyDescriptor each : props) {
             propNames.add(each.getPropertyName());
         }
-        Assert.assertTrue(propNames.contains("addressline1")); // annotated at field level
+        Assert.assertTrue(propNames.contains("addressline1")); // annotated at
+                                                               // field level
         Assert.assertTrue(propNames.contains("addressline2"));
         Assert.assertTrue(propNames.contains("zipCode"));
         Assert.assertTrue(propNames.contains("country"));
-        Assert.assertTrue(propNames.contains("city"));       // annotated at method level
+        Assert.assertTrue(propNames.contains("city")); // annotated at method
+                                                       // level
         Assert.assertEquals(5, props.size());
 
-        ElementDescriptor desc = validator.getConstraintsForClass(Address.class)
-              .getConstraintsForProperty("addressline1");
+        ElementDescriptor desc =
+            validator.getConstraintsForClass(Address.class).getConstraintsForProperty("addressline1");
         Assert.assertNotNull(desc);
         boolean found = false;
-        for (ConstraintDescriptor each : desc.getConstraintDescriptors()) {
-            if (each.getConstraintValidatorClasses().get(0)
-                  .equals(SizeValidatorForString.class)) {
+        for (ConstraintDescriptor<?> each : desc.getConstraintDescriptors()) {
+            if (each.getConstraintValidatorClasses().get(0).equals(SizeValidatorForString.class)) {
                 Assert.assertTrue(each.getAttributes().containsKey("max"));
                 assertEquals(30, each.getAttributes().get("max"));
                 found = true;
@@ -148,7 +193,6 @@ public class Jsr303Test extends TestCase
     }
 
     public void testValidateMultiValuedConstraints() {
-        Validator validator = getValidator();
         Engine engine = new Engine();
         engine.serialNumber = "abcd-defg-0123";
         Set<ConstraintViolation<Engine>> violations;
@@ -158,8 +202,7 @@ public class Jsr303Test extends TestCase
         engine.serialNumber = "!)/(/()";
         violations = validator.validate(engine);
         assertEquals(2, violations.size());
-        for (String msg : new String[]{"must contain alphabetical characters only",
-              "must match ....-....-...."}) {
+        for (String msg : new String[] { "must contain alphabetical characters only", "must match ....-....-...." }) {
             assertNotNull(TestUtils.getViolationWithMessage(violations, msg));
         }
     }
@@ -170,7 +213,6 @@ public class Jsr303Test extends TestCase
         entity.setProperty("201");
         entity.setLongValue(301);
         entity.setDecimalValue(new BigDecimal(401));
-        Validator validator = getValidator();
         Set<ConstraintViolation<MaxTestEntity>> violations = validator.validate(entity);
         assertEquals(4, violations.size());
 
@@ -180,10 +222,9 @@ public class Jsr303Test extends TestCase
             fail("UnexpectedTypeException expected but not thrown");
         } catch (UnexpectedTypeException ex) {
             // we expected this
-            assertEquals("No validator could be found for type java.lang.Object. " +
-                  "See: @Max at private java.lang.Object " +
-                  "org.apache.bval.jsr303.example." + "NoValidatorTestEntity.anything",
-                  ex.getMessage());
+            assertEquals("No validator could be found for type java.lang.Object. "
+                + "See: @Max at private java.lang.Object " + "org.apache.bval.jsr303.example."
+                + "NoValidatorTestEntity.anything", ex.getMessage());
         }
     }
 
@@ -197,7 +238,7 @@ public class Jsr303Test extends TestCase
         en.fa = new float[3];
         en.it = new int[3];
         en.la = new long[3];
-        en.map = new HashMap();
+        en.map = new HashMap<String, String>();
         en.map.put("1", "1");
         en.map.put("3", "3");
         en.map.put("2", "2");
@@ -205,15 +246,14 @@ public class Jsr303Test extends TestCase
         en.oa2 = new Integer[3];
         en.sa = new short[3];
         en.text = "123";
-        Set<ConstraintViolation<SizeTestEntity>> vi = getValidator().validate(en);
+        Set<ConstraintViolation<SizeTestEntity>> vi = validator.validate(en);
         assertEquals(13, vi.size());
     }
-    
+
     /**
      * JSR-303 Section 5.1.c, IllegalArgumentException should be thrown
      */
     public void testGetConstraintsForNullClass() {
-        Validator validator = getValidator();
         try {
             validator.getConstraintsForClass(null);
             Assert.fail("No exception thrown on Validator.getConstraintsForClass(null)");
@@ -223,8 +263,4 @@ public class Jsr303Test extends TestCase
         }
     }
 
-    private Validator getValidator() {
-//        return Validation.buildDefaultValidatorFactory().getValidator();
-        return ApacheValidatorFactory.getDefault().getValidator();
-    }
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/PayloadTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/PayloadTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/PayloadTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/PayloadTest.java Tue Sep 14 02:43:58 2010
@@ -18,11 +18,14 @@
  */
 package org.apache.bval.jsr303;
 
+import java.util.Locale;
 import java.util.Set;
 
 import javax.validation.ConstraintViolation;
 import javax.validation.Payload;
+import javax.validation.Validation;
 import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
 import javax.validation.constraints.NotNull;
 
 import junit.framework.TestCase;
@@ -35,10 +38,34 @@ import org.apache.bval.jsr303.util.TestU
  * through the ConstraintViolation objects<br/>
  */
 public class PayloadTest extends TestCase {
-    private Validator validator;
+    static ValidatorFactory factory;
 
-    protected void setUp() {
-        validator = ApacheValidatorFactory.getDefault().getValidator();
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
+        return factory.getValidator();
     }
 
     static class Severity {
@@ -74,7 +101,7 @@ public class PayloadTest extends TestCas
         Address address = new Address(null, null);
         violations = validator.validate(address);
         assertEquals(2, violations.size());
-        ConstraintViolation vio;
+        ConstraintViolation<?> vio;
         vio = TestUtils.getViolation(violations, "zipCode");
         assertNotNull(vio);
         assertEquals(1, vio.getConstraintDescriptor().getPayload().size());

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java Tue Sep 14 02:43:58 2010
@@ -23,8 +23,12 @@ import junit.framework.TestCase;
 import org.apache.bval.util.PropertyAccess;
 
 import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
 import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
 import javax.validation.constraints.Pattern;
+
+import java.util.Locale;
 import java.util.Set;
 
 /**
@@ -34,6 +38,35 @@ import java.util.Set;
  * Time: 14:21:45<br>
  */
 public class TckReproducerTest extends TestCase {
+    static ValidatorFactory factory;
+
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
+        return factory.getValidator();
+    }
 
     public static <T> void assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations,
         int expectedViolations) {
@@ -41,12 +74,7 @@ public class TckReproducerTest extends T
             + violations.size(), expectedViolations, violations.size());
     }
 
-    private Validator getValidator() {
-        return ApacheValidatorFactory.getDefault().getValidator();
-    }
-
     public void testPropertyAccessOnNonPublicClass() throws Exception {
-        Validator validator = getValidator();
         Car car = new Car("USd-298");
         assertEquals(car.getLicensePlateNumber(), PropertyAccess.getProperty(car, "licensePlateNumber"));
 

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidatorResolutionTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidatorResolutionTest.java?rev=996741&r1=996740&r2=996741&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidatorResolutionTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidatorResolutionTest.java Tue Sep 14 02:43:58 2010
@@ -40,14 +40,12 @@ import javax.validation.constraints.NotN
 
 import junit.framework.TestCase;
 
-
 /**
  * Checks the correct behavior of the validator resolution algorithm.
  * 
  * @author Carlos Vara
  */
 public class ValidatorResolutionTest extends TestCase {
-
     static ValidatorFactory factory;
 
     static {
@@ -55,7 +53,26 @@ public class ValidatorResolutionTest ext
         ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
     }
 
-    private Validator getValidator() {
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
 
@@ -64,7 +81,6 @@ public class ValidatorResolutionTest ext
      * only available validator is associated with a different annotation type.
      */
     public void testInvalidValidator() {
-        Validator validator = getValidator();
         try {
             validator.validate(new Person());
             fail("No exception thrown, but no valid validator available.");
@@ -72,30 +88,32 @@ public class ValidatorResolutionTest ext
             // correct
         }
     }
-    
-    
+
     public static class Person {
         @PersonName
         public String name;
     }
-    
-    @Constraint(validatedBy = {InvalidPersonNameValidator.class})
+
+    @Constraint(validatedBy = { InvalidPersonNameValidator.class })
     @Documented
-    @Target({ METHOD, FIELD, TYPE })
+    @Target( { METHOD, FIELD, TYPE })
     @Retention(RUNTIME)
     public static @interface PersonName {
         String message() default "Wrong person name";
-        Class<?>[] groups() default { };
+
+        Class<?>[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class InvalidPersonNameValidator implements ConstraintValidator<NotNull, String> {
         public void initialize(NotNull constraintAnnotation) {
             // Nothing
         }
+
         public boolean isValid(String value, ConstraintValidatorContext context) {
             return true;
         }
     }
-    
+
 }



Mime
View raw message