ComponentFactoryIntrospector { public Class<?> targetTypeForComponentFactory(Class<?> type) { Class<?> c = targetTypeForComponentFactory0(type); if (c == null) { throw new ComponentRegistrationException("Class does not implements ComponentFactory " + type); } return c; }  Class<?> targetTypeForComponentFactory(Class<?> type);  }
@Test public void shouldExtractTargetTypeFromGenericDefinition() { Object targetType = new ComponentFactoryIntrospector().targetTypeForComponentFactory(MyFactory.class); assertEquals(NeedsCustomInstantiation.class, targetType); }
@Test(expected = ComponentRegistrationException.class) public void shouldRequireGenericTypeInformationToBePresent() { new ComponentFactoryIntrospector().targetTypeForComponentFactory(FactoryWithoutTargetType.class); }
@Test public void shoudWorkWithSubclassesOfComponenetFactoryImplementations() { Class<?> c = new ComponentFactoryIntrospector().targetTypeForComponentFactory(ClassThatImplementsCFExtending.class); assertEquals(String.class, c); }
@Test public void shoudWorkWithImplementationsOfComponenetFactorySubinterfacesImplementations() { Class<?> c = new ComponentFactoryIntrospector().targetTypeForComponentFactory(ClassThatImplementsCFIndirectly.class); assertEquals(String.class, c); }
@Test(expected = ComponentRegistrationException.class) public void shoudNotWorkWithClassesThatDoesNotImplementComponentFactory() { new ComponentFactoryIntrospector().targetTypeForComponentFactory(ClassThatIsNotCFAtAll.class); }