ReflectionBasedNullHandler extends ObjectNullHandler { Method findSetter(Object target, String propertyCapitalized, Class<? extends Object> argument) { Class<? extends Object> targetClass = target.getClass(); if (proxifier.isProxy(target)) { targetClass = targetClass.getSuperclass(); } return new Mirror().on(targetClass).reflect().method("set" + propertyCapitalized).withArgs(argument); } ReflectionBasedNullHandler(Proxifier proxifier); @Override Object nullPropertyValue(Map context, Object target, Object property);  }
@Test public void shouldFoundASetter() throws Exception { final House aSimpleJavaBeans = new House(); final List<Method> methodsOfHouseClass = Arrays.asList(House.class.getMethods()); Method foundMethod = new ReflectionBasedNullHandler(proxifier).findSetter(aSimpleJavaBeans, "Mouse", Mouse.class); assertThat(methodsOfHouseClass, hasItem(foundMethod)); assertThat(foundMethod.toGenericString(), startsWith("public void ")); assertThat(foundMethod.getName(), is(startsWith("setMouse"))); }
@Test public void shouldFoundASetterEvenWithAProxyObject() throws Exception { final House aSimpleJavaBeans = new House(); House beanProxified = proxify(aSimpleJavaBeans); final List<Method> methodsOfHouseClass = Arrays.asList(House.class.getMethods()); Method foundMethod = new ReflectionBasedNullHandler(proxifier).findSetter(beanProxified, "Mouse", Mouse.class); assertThat(methodsOfHouseClass, hasItem(foundMethod)); assertThat(foundMethod.toGenericString(), startsWith("public void ")); assertThat(foundMethod.getName(), is(startsWith("setMouse"))); }