### Question:
ClassUtils { static Method getSetter(Class<?> targetClass, String propertyName, Class<?> type) { if (targetClass == null) { return null; } String setterMethodName = setterName(propertyName); try { Method setter = targetClass.getMethod(setterMethodName, type); logger.debug("Found public setter {} in class {}", setterMethodName, setter.getDeclaringClass().getName()); return setter; } catch (NoSuchMethodException e) { logger.debug("Failed to found public setter {} in class {}", setterMethodName, targetClass.getName()); } while (targetClass != null) { try { Method setter = targetClass.getDeclaredMethod(setterMethodName, type); logger.debug("Found setter {} in class {}", setterMethodName, targetClass.getName()); return setter; } catch (NoSuchMethodException e) { logger.debug("Failed to found setter {} in class {}", setterMethodName, targetClass.getName()); } targetClass = targetClass.getSuperclass(); } return null; } private  ClassUtils();   }### Answer:
@Test public void testGetSetter() { Method method = ClassUtils.getSetter(TestBean.class, "strField", String.class); Assert.assertEquals(method.getName(), "setStrField"); }
@Test public void testGetSetterOfWrongType() { Method method = ClassUtils.getSetter(TestBean.class, "strField", int.class); Assert.assertEquals(method, null); }
@Test public void testGetNonExistingSetter() { Method method = ClassUtils.getSetter(TestBean.class, "someNoneExistng", int.class); Assert.assertEquals(method, null); }
@Test public void testGetInheritedSetter() { Method method = ClassUtils.getSetter(InheritedTestBean.class, "strField", String.class); Assert.assertEquals(method.getName(), "setStrField"); }