ConstraintValidatorsUtils { static Object getPropertyValue(Object bean, String propertyName) { if (bean == null || isEmpty(propertyName)) { return null; } try { PropertyDescriptor property = new PropertyDescriptor(propertyName, bean .getClass()); Method getter = property.getReadMethod(); return getter.invoke(bean); } catch (Exception e) { throw reportFailedToInitialize(e); } } private  ConstraintValidatorsUtils();   }
@Test public void testGetPropertyValueBeanAndPropertyNameNotNull() throws Exception { FooBean foo = new FooBean(); foo.setBar("test"); Object o = ConstraintValidatorsUtils.getPropertyValue(foo, "bar"); assertThat(o, notNullValue()); }
@Test public void testGetPropertyValueBeanNull() throws Exception { Object o = ConstraintValidatorsUtils.getPropertyValue(null, "bar"); assertThat(o, nullValue()); }
@Test public void testGetPropertyValuePropertyNameNull() throws Exception { Object o = ConstraintValidatorsUtils.getPropertyValue(new FooBean(), null); assertThat(o, nullValue()); }