Assert.assertEquals(4, bookBeanDescriptor.getConstrainedProperties().size());
// not a property
Assert.assertTrue(bookBeanDescriptor.getConstraintsForProperty("doesNotExist") == null);
// property with no constraint
Assert.assertTrue(bookBeanDescriptor.getConstraintsForProperty("description") == null);
PropertyDescriptor propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("title");
Assert.assertEquals(2, propertyDescriptor.getConstraintDescriptors().size());
Assert.assertTrue("title".equals(propertyDescriptor.getPropertyName()));
// assuming the implementation returns the NotEmpty constraint first
Iterator<ConstraintDescriptor<?>> iter = propertyDescriptor.getConstraintDescriptors().iterator();
ConstraintDescriptor<?> constraintDescriptor = null;
while (iter.hasNext()) {
constraintDescriptor = iter.next();
if (constraintDescriptor.getAnnotation().annotationType().equals(NotNull.class)) {
break;
}
}
Assert.assertTrue(constraintDescriptor != null);
Assert.assertTrue(constraintDescriptor.getGroups().size() == 1); // "first"
Assert.assertEquals(NotNullValidator.class, constraintDescriptor.getConstraintValidatorClasses().get(0));
// assuming the implementation returns the Size constraint first
propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("subtitle");
Iterator<ConstraintDescriptor<?>> iterator = propertyDescriptor.getConstraintDescriptors().iterator();
constraintDescriptor = iterator.next();
Assert.assertTrue(constraintDescriptor.getAnnotation().annotationType().equals(Size.class));
Assert.assertTrue(((Integer) constraintDescriptor.getAttributes().get("max")) == 30);
Assert.assertTrue(constraintDescriptor.getGroups().size() == 1);
propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("author");
Assert.assertTrue(propertyDescriptor.getConstraintDescriptors().size() == 1);
Assert.assertTrue(propertyDescriptor.isCascaded());
Assert.assertNull(bookBeanDescriptor.getConstraintsForProperty("unconstraintField"));
}