Add unit test for component taking an interface.
@@ -104,6 +104,17 @@ public class ComponentGraphTest {
assertNotNull(instance);
}
+ @Test
+ public void interface_implementation_can_be_injected() {
+ ComponentGraph componentGraph = new ComponentGraph();
+ componentGraph.add(mockComponentNode(ComponentImpl.class));
+ componentGraph.add(mockComponentNode(ComponentTakingInterface.class));
+ componentGraph.complete();
+
+ ComponentTakingInterface instance = componentGraph.getInstance(ComponentTakingInterface.class);
+ assertTrue(instance.injected instanceof ComponentImpl);
+ }
+
@Test
public void all_components_of_a_type_can_be_injected() {
ComponentGraph componentGraph = new ComponentGraph();
@@ -474,6 +485,15 @@ public class ComponentGraphTest {
public static class SimpleDerivedComponent extends SimpleComponent {
}
+ public interface ComponentBase { }
+ public static class ComponentImpl implements ComponentBase { }
+ public static class ComponentTakingInterface {
+ ComponentBase injected;
+ public ComponentTakingInterface(ComponentBase componentBase) {
+ injected = componentBase;
+ }
+ }
+
public static class ComponentTakingConfig extends SimpleComponent {
private final TestConfig config;
