[picocontainer-scm] [5571] java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/ReinjectionTestCase.java: type conversion and paranamer together

paul-yCVjj/[email protected]
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <[email protected]>
Revision 5571
Author paul
Date 2010-01-01 19:07:30 -0600 (Fri, 01 Jan 2010)

Log Message

type conversion and paranamer together

Modified Paths

- java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/ReinjectionTestCase.java

Diff

Modified: java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/ReinjectionTestCase.java (5570 => 5571)

--- java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/ReinjectionTestCase.java 2010-01-01 23:49:33 UTC (rev 5570)
+++ java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/ReinjectionTestCase.java 2010-01-02 01:07:30 UTC (rev 5571)
@@ -70,6 +70,11 @@
return Integer.parseInt(s) / 2;
}

+ public int doInt(int s) {
+ this.string = "i="+ s;
+ return s/2;
+ }
+
public Object getBar() {
return bar;
}
@@ -172,6 +177,35 @@

}

+ @Test
+ public void confirmThatReinjectionCanLeverageParameterNamesForDisambiguationWithTypeConversion() throws NoSuchMethodException {
+ MethodInjection methodInjection = new MethodInjection(NeedsShoe.class.getMethod("doInt", int.class));
+ DefaultPicoContainer parent = new DefaultPicoContainer(new Caching().wrap(new ConstructorInjection()));
+
+ // parameter name leverage can't work on interfaces if using bytecode retrieval technique
+
+ parent.addComponent(NeedsShoe.class);
+ parent.addComponent(Shoe.class);
+ parent.addComponent("a", "1333");
+ parent.addComponent("s", "12");
+ parent.addComponent("tjklhjkjhkjh", "44");
+
+ NeedsShoe needsShoe = parent.getComponent(NeedsShoe.class);
+ assertNotNull(needsShoe.bar);
+ assertTrue(needsShoe.string == null);
+
+ Reinjection reinjection = new Reinjection(methodInjection, parent);
+ TransientPicoContainer tpc = new TransientPicoContainer(reinjection, parent);
+ tpc.as(Characteristics.USE_NAMES).addComponent(NeedsShoe.class);
+
+ NeedsShoe needsShoe2 = tpc.getComponent(NeedsShoe.class);
+ assertSame(needsShoe, needsShoe2);
+ assertNotNull(needsShoe2.bar);
+ assertNotNull(needsShoe2.string);
+ assertEquals("i=12", needsShoe2.string);
+
+ }
+
@Test public void testCachedComponentCanBeReinjectedByATransientReflectionMethodReinjector() {
cachedComponentCanBeReinjectedByATransientReinjector(new MethodInjection(DOIT_METHOD));
}

----------

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.