@Test public void testAnnotatedFieldInjectionComponentCanDependOnConfig() { CommandLineArgumentsPicoContainer apc = new CommandLineArgumentsPicoContainer(new String[] {"a=a", "b=2", "c=true"}); DefaultPicoContainer pico = new DefaultPicoContainer(new AnnotatedFieldInjection(), apc); pico.addConfig("zzz", "zzz"); pico.as(Characteristics.USE_NAMES).addComponent(NeedsAFew3.class); NeedsAFew3 needsAFew = pico.getComponent(NeedsAFew3.class); assertNotNull(needsAFew); assertEquals("a", needsAFew.a); assertEquals(2, needsAFew.b); assertEquals(true, needsAFew.c); }
@Test public void testComponentWithCtorAndNamedFieldWorkToegether() throws NoSuchMethodException { DefaultPicoContainer dpc = new DefaultPicoContainer( new CompositeInjection(new ConstructorInjection(), new NamedFieldInjection()), new NullLifecycleStrategy(), new EmptyPicoContainer()); dpc.addComponent(Bar.class); dpc.addConfig("one", "1"); dpc.addConfig("two", "2"); dpc.as(injectionFieldNames("one", "two")).addComponent(Foo4.class); Foo4 foo4 = dpc.getComponent(Foo4.class); assertNotNull(foo4); assertNotNull(foo4.bar); assertNotNull(foo4.one); assertEquals("1", foo4.one); assertNotNull(foo4.two); assertEquals("2", foo4.two); }