bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r997034 - in /incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303: BeanDescriptorTest.java Jsr303Test.java util/TestUtils.java
Date Tue, 14 Sep 2010 18:42:19 GMT
Author: mbenson
Date: Tue Sep 14 18:42:19 2010
New Revision: 997034

URL: http://svn.apache.org/viewvc?rev=997034&view=rev
Log:
add assertions wrt immutability of jsr303 metadata; tests now fail

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/Jsr303Test.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=997034&r1=997033&r2=997034&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 18:42:19 2010
@@ -43,6 +43,8 @@ import javax.validation.metadata.Propert
 import javax.validation.metadata.Scope;
 import javax.validation.metadata.ElementDescriptor.ConstraintFinder;
 
+import org.apache.bval.jsr303.util.TestUtils;
+
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
@@ -185,6 +187,7 @@ public class BeanDescriptorTest extends 
 
         constraints = nameDescriptor.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
         Assert.assertEquals("Incorrect number of descriptors", 0, constraints.size());
+        TestUtils.failOnModifiable(constraints, "constraintFinder constraintDescriptors");
     }
 
     public static class Form {

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=997034&r1=997033&r2=997034&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 18:42:19 2010
@@ -134,6 +134,8 @@ public class Jsr303Test extends TestCase
 
     public void testMetadataAPI_Book() {
         Assert.assertNotNull(validator.getConstraintsForClass(Book.class));
+        // not necessary for implementation correctness, but we'll test
+        // nevertheless:
         Assert.assertSame(validator.getConstraintsForClass(Book.class), validator.getConstraintsForClass(Book.class));
         BeanDescriptor bc = validator.getConstraintsForClass(Book.class);
         // assertEquals(ElementType.TYPE, bc.getElementType());
@@ -141,6 +143,7 @@ public class Jsr303Test extends TestCase
         // assertEquals(false, bc.isCascaded());
         // assertEquals("", bc.getPropertyPath());
         Assert.assertTrue(bc.getConstraintDescriptors() != null);
+        TestUtils.failOnModifiable(bc.getConstraintDescriptors(), "beanDescriptor constraintDescriptors");
     }
 
     public void testMetadataAPI_Engine() {
@@ -155,17 +158,19 @@ public class Jsr303Test extends TestCase
         Assert.assertFalse(validator.getConstraintsForClass(Address.class).getConstraintDescriptors().isEmpty());
 
         Set<PropertyDescriptor> props = validator.getConstraintsForClass(Address.class).getConstrainedProperties();
+        TestUtils.failOnModifiable(props, "beanDescriptor constrainedProperties");
         Set<String> propNames = new HashSet<String>(props.size());
         for (PropertyDescriptor each : props) {
+            TestUtils.failOnModifiable(each.getConstraintDescriptors(), "propertyDescriptor
constraintDescriptors");
             propNames.add(each.getPropertyName());
         }
         Assert.assertTrue(propNames.contains("addressline1")); // annotated at
-                                                               // field level
+        // 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
+        // level
         Assert.assertEquals(5, props.size());
 
         ElementDescriptor desc =

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java?rev=997034&r1=997033&r2=997034&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java
Tue Sep 14 18:42:19 2010
@@ -18,9 +18,13 @@
  */
 package org.apache.bval.jsr303.util;
 
-import javax.validation.ConstraintViolation;
+import java.util.Collection;
 import java.util.Set;
 
+import javax.validation.ConstraintViolation;
+
+import org.junit.Assert;
+
 /**
  * Description: <br/>
  */
@@ -48,4 +52,23 @@ public class TestUtils {
         }
         return null;
     }
+
+    /**
+     * assume set addition either does nothing, returning false per collection
+     * contract, or throws an Exception; in either case size should remain
+     * unchanged
+     * 
+     * @param collection
+     */
+    public static void failOnModifiable(Collection<?> collection, String description)
{
+        int size = collection.size();
+        try {
+            Assert
+                .assertFalse(String.format("should not permit modification to %s", description),
collection.add(null));
+        } catch (Exception e) {
+            // okay
+        }
+        Assert.assertEquals("constraint descriptor set size changed", size, collection.size());
+    }
+
 }



Mime
View raw message