DiResolverUtil { static void validateGetterReturnsNull(PmObject pm, Method getter) { if (getter == null) { return; } Object value = null; try { value = getter.invoke(pm); } catch (Exception ex) { throw new PmRuntimeException(pm, "Can't invoke getter '" + getter.getName() + "' in class '" + pm.getClass().getName() + "'.", ex); } if (value != null) { throw new PmRuntimeException(pm, "Can't perform @PmInject for '" + PrefixUtil.propNameForGetter(getter.getName()) + "'. It already has value: " + value ); } }  static DiResolver[] getDiResolvers(Class<?> forClass);  }
@Test public void validateGetterReturnsNullThrowsExceptionWhenGetterReturnsValue() { expectedException.expect(PmRuntimeException.class); expectedException.expectMessage("Can't perform @PmInject for 'mySetterInitializedNullProp'. It already has value: [faking some preexisting initialization] - Exception context: Class: 'org.pm4j.core.pm.impl.inject.DiResolverUtilTest$MyPm' PM: 'org.pm4j.core.pm.impl.inject.DiResolverUtilTest$MyPm'"); myPm.setMySetterInitializedNullProp("[faking some preexisting initialization]"); DiResolverUtil.validateGetterReturnsNull(myPm, PrefixUtil.findGetterForSetter(mySetterInitializedNullPropSetter)); }
@Test public void validateGetterReturnsNullThrowsExceptionWhenGetterCantBeInvoked() { expectedException.expect(PmRuntimeException.class); expectedException.expectMessage("Can't invoke getter 'getMySetterInitializedFakeProp' in class 'org.pm4j.core.pm.impl.inject.DiResolverUtilTest$MyPm'."); DiResolverUtil.validateGetterReturnsNull(myPm, PrefixUtil.findGetterForSetter(mySetterInitializedFakeProp)); }
@Test public void validateGetterReturnsNullDoesAcceptNullValue() { myPm.setMySetterInitializedNullProp(null); DiResolverUtil.validateGetterReturnsNull(myPm, PrefixUtil.findGetterForSetter(mySetterInitializedNullPropSetter)); }
@Test public void validateGetterReturnsNullDoesDoesNotThrowExceptionWhenThereIsNoGetter() { DiResolverUtil.validateGetterReturnsNull(myPm, PrefixUtil.findGetterForSetter(mySetterInitializedPropWithoutGetterSetter)); }