.lookingAt(scope) .declaredOn(declaredOnTypes.toArray(new ElementType[]{})) .unorderedAndMatchingGroups(matchingGroups.toArray(new Class<?>[]{}));
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "g") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "c") public void testFindConstraintsForMethodDefinedOnSuperTypeLookingAt() { CrossParameterDescriptor descriptor = Executables.crossParameterConstrainedMethodFromSuperType() .getCrossParameterDescriptor(); Set<ConstraintDescriptor<?>> constraints = descriptor.findConstraints() .lookingAt( Scope.LOCAL_ELEMENT ) .getConstraintDescriptors(); assertEquals( constraints.size(), 0, "Should have no local constraints" ); constraints = descriptor.findConstraints() .lookingAt( Scope.HIERARCHY ) .getConstraintDescriptors(); assertEquals( constraints.size(), 1, "Should have constraints" ); ConstraintDescriptor<?> constraint = constraints.iterator().next(); assertEquals( constraint.getAnnotation().annotationType(), MyCrossParameterConstraint.class, "Wrong constraint type" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "g") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "c") public void testFindConstraintsForMethodLookingAt() { CrossParameterDescriptor descriptor = Executables.methodOverridingCrossParameterConstrainedMethod() .getCrossParameterDescriptor(); Set<ConstraintDescriptor<?>> constraints = descriptor.findConstraints() .lookingAt( Scope.LOCAL_ELEMENT ) .getConstraintDescriptors(); assertEquals( constraints.size(), 0, "Should have no local constraints" ); constraints = descriptor.findConstraints() .lookingAt( Scope.HIERARCHY ) .getConstraintDescriptors(); assertEquals( constraints.size(), 1, "Should have constraints" ); ConstraintDescriptor<?> constraint = constraints.iterator().next(); assertEquals( constraint.getAnnotation().annotationType(), MyCrossParameterConstraint.class, "Wrong constraint type" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "d") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "f") public void testDeclaredOn() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SubClass.class ); assertNotNull( beanDescriptor ); Set<ConstraintDescriptor<?>> descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.HIERARCHY ) .declaredOn( ElementType.TYPE ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 0 ); descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.HIERARCHY ) .declaredOn( ElementType.METHOD ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 0 ); descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.HIERARCHY ) .declaredOn( ElementType.FIELD ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 2 ); }
@Test @SpecAssertion(section = "5.2", id = "e") public void testDeclaredOn() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SubClass.class ); assertNotNull( beanDescriptor ); Set<ConstraintDescriptor<?>> descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.HIERARCHY ) .declaredOn( ElementType.TYPE ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 0 ); descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.HIERARCHY ) .declaredOn( ElementType.METHOD ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 0 ); descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.HIERARCHY ) .declaredOn( ElementType.FIELD ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 2 ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "d") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "g") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "g") public void testFindConstraintsForMethodDefinedOnSuperTypeLookingAt() { MethodDescriptor crossParameterConstrainedDescriptor = Executables.crossParameterConstrainedMethodFromSuperType(); assertEquals( crossParameterConstrainedDescriptor.findConstraints() .lookingAt( Scope.LOCAL_ELEMENT ) .getConstraintDescriptors() .size(), 0, "Should have no local constraints" ); assertTrue( crossParameterConstrainedDescriptor.findConstraints().lookingAt( Scope.HIERARCHY ) .getConstraintDescriptors() .isEmpty(), "Should have no hierarchy constraint" ); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "d") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "g") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "g") public void testFindConstraintsForMethodLookingAt() { MethodDescriptor crossParameterConstrainedDescriptor = Executables.methodOverridingCrossParameterConstrainedMethod(); assertEquals( crossParameterConstrainedDescriptor.findConstraints() .lookingAt( Scope.LOCAL_ELEMENT ) .getConstraintDescriptors() .size(), 0, "Should have no local constraints" ); assertTrue( crossParameterConstrainedDescriptor.findConstraints().lookingAt( Scope.HIERARCHY ) .getConstraintDescriptors() .isEmpty(), "Should have no hierarchy constraints" ); }
@Test @SpecAssertion(section = "5.2", id = "f") public void testLookingAt() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SubClass.class ); assertNotNull( beanDescriptor ); Set<ConstraintDescriptor<?>> descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.HIERARCHY ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 2 ); descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.LOCAL_ELEMENT ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 1 ); } }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "d") @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "g") public void testLookingAt() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SubClass.class ); assertNotNull( beanDescriptor ); Set<ConstraintDescriptor<?>> descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.HIERARCHY ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 2 ); descriptors = beanDescriptor.getConstraintsForProperty( "myField" ) .findConstraints() .lookingAt( Scope.LOCAL_ELEMENT ) .getConstraintDescriptors(); assertTrue( descriptors.size() == 1 ); } }