ReflectionBasedNullHandler extends ObjectNullHandler { Method findGetter(Object target, String propertyCapitalized) { Class<? extends Object> targetClass = target.getClass(); if (proxifier.isProxy(target)) { targetClass = targetClass.getSuperclass(); } return new Mirror().on(targetClass).reflect().method("get" + propertyCapitalized).withoutArgs(); } ReflectionBasedNullHandler(Proxifier proxifier); @Override Object nullPropertyValue(Map context, Object target, Object property);  }
@Test public void shouldFoundAGetter() throws Exception { final House aSimpleJavaBeans = new House(); final List<Method> methodsOfHouseClass = Arrays.asList(House.class.getMethods()); Method foundMethod = new ReflectionBasedNullHandler(proxifier).findGetter(aSimpleJavaBeans, "Mouse"); assertThat(methodsOfHouseClass, hasItem(foundMethod)); assertTrue(Mouse.class.isAssignableFrom(foundMethod.getReturnType())); assertThat(foundMethod.getName(), is(startsWith("getMouse"))); }
@Test public void shouldFoundAGetterWithAProxyObject() 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).findGetter(beanProxified, "Mouse"); assertThat(methodsOfHouseClass, hasItem(foundMethod)); assertTrue(Mouse.class.isAssignableFrom(foundMethod.getReturnType())); assertThat(foundMethod.getName(), is(startsWith("getMouse"))); }