@Test public void test() { componentMap.put("myNameIsA", new TestComponent("A")); ComponentInjector injector = new ComponentInjector(componentMap); InjectTarget1 target1 = new InjectTarget1(); injector.inject(target1); assertEquals("A", target1.tc.getId()); }
@Test public void testNamedInject() { componentMap.put("myNameIsA", new TestComponent("A")); componentMap.put("myNameIsB", new TestComponent("B")); ComponentInjector injector = new ComponentInjector(componentMap); InjectTarget2 target2 = new InjectTarget2(); injector.inject(target2); assertEquals("B", target2.tc.getId()); }
@Test public void wrongNamedInject() { componentMap.put("myNameIsAAA", new TestComponent("A")); componentMap.put("MyNameIsB", new TestComponent("B")); ComponentInjector injector = new ComponentInjector(componentMap); InjectTarget2 target2 = new InjectTarget2(); try { injector.inject(target2); fail("MisconfigurationException will occur"); } catch (MisconfigurationException ex) { assertTrue(ex.getSolution().contains("MyNameIsB")); } }