### Question:
Validation { public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyPath, Class<?>... groups) { Set<ConstraintViolation<T>> violations = new HashSet<ConstraintViolation<T>>(); try { int currentIndex = -1; String currentPropertyPath; do { currentIndex = propertyPath.indexOf(".", ++currentIndex); if (currentIndex >= 0) { currentPropertyPath = propertyPath.substring(0, currentIndex); } else { currentPropertyPath = propertyPath; } Set<ConstraintViolation<T>> currentViolations = validator.validateProperty(object, currentPropertyPath, groups); ConstraintViolation<T> notNullViolation = findNotNullViolation(currentViolations); if (notNullViolation == null) { violations = currentViolations; } else { violations.add(notNullViolation); break; } } while (currentIndex >= 0); } catch (IllegalArgumentException e) { } return violations; }  @PostConstruct void postConstruct(); Set<ConstraintViolation<T>> validate(T object, Class<?>... groups); Set<ConstraintViolation<T>> validateProperty(T object, String propertyPath, Class<?>... groups); Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups); BeanDescriptor getConstraintsForClass(Class<?> clazz); T unwrap(Class<T> type); boolean isCascaded(Class beanClass, String propertyName); boolean isRequired(Class beanClass, String propertyName); boolean hasAnnotation(Class beanClass, String propertyName, Class annotationClass);  }### Answer:
@Test public void validateRootProperty() { RootBean rootBean = new RootBean(); NestedBean nestedBean = new NestedBean(); nestedBean.setProperty("12"); rootBean.setNestedBean(nestedBean); Set<ConstraintViolation<RootBean>> violations = validation.validateProperty(rootBean, "nestedBean"); Assert.assertTrue(violations.isEmpty()); }
@Test public void validateInvalidRootNotNullProperty() { RootBean rootBean = new RootBean(); Set<ConstraintViolation<RootBean>> violations = validation.validateProperty(rootBean, "notNullNestedBean"); Assert.assertTrue(violations.size() == 1); }
@Test public void validateInvalidNestedProperty() { RootBean rootBean = new RootBean(); NestedBean nestedBean = new NestedBean(); nestedBean.setProperty("12"); rootBean.setNestedBean(nestedBean); Set<ConstraintViolation<RootBean>> violations = validation.validateProperty(rootBean, "nestedBean.property"); Assert.assertTrue(violations.size() == 1); }
@Test public void validateInvalidNestedNullProperty() { RootBean rootBean = new RootBean(); NestedBean nestedBean = new NestedBean(); rootBean.setNestedBean(nestedBean); Set<ConstraintViolation<RootBean>> violations = validation.validateProperty(rootBean, "nestedBean.property"); Assert.assertTrue(violations.size() == 1); }
@Test public void validateInvalidNotNullNullNestedProperty() { RootBean rootBean = new RootBean(); Set<ConstraintViolation<RootBean>> violations = validation.validateProperty(rootBean, "notNullNestedBean.property"); Assert.assertTrue(violations.size() == 1); }
@Test public void validateInvalidOptionalNullNestedProperty() { RootBean rootBean = new RootBean(); Set<ConstraintViolation<RootBean>> violations = validation.validateProperty(rootBean, "notNullNestedBean.optionalProperty"); Assert.assertTrue(violations.size() == 1); }
@Test public void validateNestedPropertyWithNull() { RootBean rootBean = new RootBean(); Set<ConstraintViolation<RootBean>> violations = validation.validateProperty(rootBean, "nestedBean.property"); Assert.assertTrue(violations.isEmpty()); }
@Test public void validateIgnoredNestedProperty() { RootBean rootBean = new RootBean(); NestedBean nestedBean = new NestedBean(); nestedBean.setProperty("12"); rootBean.setIgnoredNestedBean(nestedBean); Set<ConstraintViolation<RootBean>> violations = validation.validateProperty(rootBean, "ignoredNestedBean.property"); Assert.assertTrue(violations.isEmpty()); }