### Question:
ClassUtils { static Method getGetter(Class<?> targetClass, String propertyName) { if (targetClass == null) { return null; } final String getterName = getterName(propertyName, false); Method result = findPublicGetter(targetClass, getterName, propertyName, false); if (result == null) { final String booleanGetterName = getterName(propertyName, true); result = findPublicGetter(targetClass, booleanGetterName, propertyName, true); if (result == null) { do { result = findNonPublicGetter(targetClass, getterName, propertyName, false); if (result == null) { result = findNonPublicGetter(targetClass, booleanGetterName, propertyName, true); } } while (result == null && (targetClass = targetClass.getSuperclass()) != null); } } return result; } private  ClassUtils();   }### Answer:
@Test public void getGetter() throws Exception { Method getter = ClassUtils.getGetter(TestBean.class, "intField"); Assert.assertEquals(getter, TestBean.class.getDeclaredMethod("getIntField")); }
@Test public void getBooleanGetter() throws Exception { Method getter = ClassUtils.getGetter(TestBean.class, "boolField"); Assert.assertEquals(getter, TestBean.class.getDeclaredMethod("isBoolField")); }
@Test public void getNonExistingGetterMethod() throws Exception { Method getter = ClassUtils.getGetter(TestBean.class, "nonExistingField"); Assert.assertEquals(getter, null); }
@Test public void getInheritedGetter() throws Exception { Method getter = ClassUtils.getGetter(InheritedTestBean.class, "intField"); Assert.assertEquals(getter, TestBean.class.getDeclaredMethod("getIntField")); }
@Test public void getProtectedGetter() throws Exception { Method getter = ClassUtils.getGetter(ProtectedTestBean.class, "field"); Assert.assertEquals(getter, ProtectedTestBean.class.getDeclaredMethod("getField")); }