@Test public void testAcceptsComponentParametersForComponent() { Reader script = new StringReader( "A = org.picocontainer.script.testmodel.A\n" + "B = org.picocontainer.script.testmodel.B\n" + "container {\n" + " component(:key => 'a1', :class => A)\n" + " component(:key => 'a2', :class => A)\n" + " component(:key => 'b1', :class => B, :parameters => [ key('a1') ])\n" + " component(:key => 'b2', :class => B, :parameters => key('a2'))\n" + "}"); PicoContainer pico = buildContainer(script, null, ASSEMBLY_SCOPE); A a1 = (A) pico.getComponent("a1"); A a2 = (A) pico.getComponent("a2"); B b1 = (B) pico.getComponent("b1"); B b2 = (B) pico.getComponent("b2"); assertNotNull(a1); assertNotNull(a2); assertNotNull(b1); assertNotNull(b2); assertSame(a1, b1.getA()); assertSame(a2, b2.getA()); assertNotSame(a1, a2); assertNotSame(b1, b2); }
@Test public void testAcceptsComponentParameterWithClassNameKey() { Reader script = new StringReader( "A = org.picocontainer.script.testmodel.A\n" + "B = org.picocontainer.script.testmodel.B\n" + "container {\n" + " component(:class => A)\n" + " component(:key => B, :class => B, :parameters => key(A))\n" + "}"); PicoContainer pico = buildContainer(script, null, ASSEMBLY_SCOPE); A a = pico.getComponent(A.class); B b = pico.getComponent(B.class); assertNotNull(a); assertNotNull(b); assertSame(a, b.getA()); }