@Test public void testConstraintWithNoGroups() { Annotation annotation = new NoMessage() { public Class<?>[] groups() { return null; } public Class<? extends Annotation> annotationType() { return this.getClass(); } }; assertFalse( constraintHelper.isConstraintAnnotation(annotation), "The constraint annotation should not be valid"); }
/** * Examines the given annotation to see whether it is a single- or multi-valued constraint * annotation. * * @param clazz the class we are currently processing * @param annotation The annotation to examine * @param type the element type on which the annotation/constraint is placed on * @return A list of constraint descriptors or the empty list in case <code>annotation</code> is * neither a single nor multi-valued annotation. */ private <A extends Annotation> List<ConstraintDescriptorImpl<?>> findConstraintAnnotations( Class<?> clazz, A annotation, ElementType type) { List<ConstraintDescriptorImpl<?>> constraintDescriptors = new ArrayList<ConstraintDescriptorImpl<?>>(); List<Annotation> constraints = new ArrayList<Annotation>(); Class<? extends Annotation> annotationType = annotation.annotationType(); if (constraintHelper.isConstraintAnnotation(annotationType) || constraintHelper.isBuiltinConstraint(annotationType)) { constraints.add(annotation); } else if (constraintHelper.isMultiValueConstraint(annotationType)) { constraints.addAll(constraintHelper.getMultiValueConstraints(annotation)); } for (Annotation constraint : constraints) { final ConstraintDescriptorImpl<?> constraintDescriptor = buildConstraintDescriptor(clazz, constraint, type); constraintDescriptors.add(constraintDescriptor); } return constraintDescriptors; }
@Test public void testConstraintWithValidInPropertyName() { Annotation annotation = new ValidProperty() { public String message() { return null; } public Class<?>[] groups() { return null; } public int validLength() { return 0; } public Class<? extends Annotation> annotationType() { return this.getClass(); } }; assertFalse( constraintHelper.isConstraintAnnotation(annotation), "The constraint annotation should not be valid"); }