You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by mb...@apache.org on 2011/02/21 19:12:10 UTC

svn commit: r1073099 - /incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java

Author: mbenson
Date: Mon Feb 21 18:12:09 2011
New Revision: 1073099

URL: http://svn.apache.org/viewvc?rev=1073099&view=rev
Log:
add a new TestUtils method

Modified:
    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/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=1073099&r1=1073098&r2=1073099&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 Mon Feb 21 18:12:09 2011
@@ -18,10 +18,13 @@
  */
 package org.apache.bval.jsr303.util;
 
+import java.lang.annotation.Annotation;
 import java.util.Collection;
 import java.util.Set;
 
 import javax.validation.ConstraintViolation;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor.ConstraintFinder;
 
 import org.junit.Assert;
 
@@ -92,4 +95,19 @@ public class TestUtils {
         Assert.assertEquals("constraint descriptor set size changed", size, collection.size());
     }
 
+    /**
+     * Assert that the specified ConstraintFinder provides constraints of each of the specified types.
+     * @param constraintFinder
+     * @param types
+     */
+    public static void assertConstraintTypesFound(ConstraintFinder constraintFinder, Class<? extends Annotation>... types) {
+        outer: for (Class<? extends Annotation> type : types) {
+            for (ConstraintDescriptor<?> descriptor : constraintFinder.getConstraintDescriptors()) {
+                if (descriptor.getAnnotation().annotationType().equals(type)) {
+                    continue outer;
+                }
+            }
+            Assert.fail(String.format("Missing expected constraint descriptor of type %s", type));
+        }
+    }
 }