[picocontainer-scm] [5570] java/2.x/trunk/pico/container: test to confirm that @Named stuff works via paranamer

paul-yCVjj/[email protected]
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <[email protected]>
Revision 5570
Author paul
Date 2010-01-01 17:49:33 -0600 (Fri, 01 Jan 2010)

Log Message

test to confirm that @Named stuff works via paranamer

Modified Paths

- java/2.x/trunk/pico/container/pom.xml

- java/2.x/trunk/pico/container/src/test/org/picocontainer/containers/PropertiesPicoContainerTestCase.java

Diff

Modified: java/2.x/trunk/pico/container/pom.xml (5569 => 5570)

--- java/2.x/trunk/pico/container/pom.xml 2010-01-01 11:54:50 UTC (rev 5569)
+++ java/2.x/trunk/pico/container/pom.xml 2010-01-01 23:49:33 UTC (rev 5570)
@@ -18,12 +18,12 @@
<artifactId>jsr250-api</artifactId>
<scope>provided</scope>
</dependency>
- <!--dependency>
+ <dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<optional>true</optional>
- </dependency-->
+ </dependency>
</dependencies>

<build>
@@ -61,6 +61,7 @@
<artifactSet>
<excludes>
<exclude>javax.annotation:jsr250-api</exclude>
+ <exclude>javax.inject:javax.inject</exclude>
</excludes>
</artifactSet>
<filters>

Modified: java/2.x/trunk/pico/container/src/test/org/picocontainer/containers/PropertiesPicoContainerTestCase.java (5569 => 5570)

--- java/2.x/trunk/pico/container/src/test/org/picocontainer/containers/PropertiesPicoContainerTestCase.java 2010-01-01 11:54:50 UTC (rev 5569)
+++ java/2.x/trunk/pico/container/src/test/org/picocontainer/containers/PropertiesPicoContainerTestCase.java 2010-01-01 23:49:33 UTC (rev 5570)
@@ -8,6 +8,8 @@
import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.Characteristics;

+import javax.inject.Named;
+
/**
* test that properties container works properly
* @author k.pribluda
@@ -54,35 +56,61 @@
container.as(Characteristics.USE_NAMES).addComponent(Dependant.class);
container.as(Characteristics.USE_NAMES).addComponent(Dependency.class);
Dependant dependant = (Dependant) container.getComponent(Dependant.class);
- System.out.println(dependant);
+ assertEquals(1, dependant.pn);
+ assertEquals("string", dependant.hn);
+
}

public static class Dependency {
- private final String name;
- public Dependency(final String agentName) {
- this.name = agentName;
- }
- public String toString() {
- return name;
- }
- }
+ private final String name;

- public static class Dependant /* */ {
- private final int number;
- private final String string;
- private final Dependency dependency;
+ public Dependency(final String agentName) {
+ this.name = agentName;
+ }

- public Dependant(final String hostName, final int portNumber, final Dependency dependency) {
- this.number = portNumber;
- this.string = hostName;
- this.dependency = dependency;
- }
+ public String toString() {
+ return name;
+ }
+ }

- public String toString() {
- return "Number: " + number + " String: " + string + " Dependency: " + dependency;
- }
- }
+ public static class Dependant {
+ final int pn;
+ final String hn;
+ final Dependency dependency;

+ public Dependant(final String hostName, final int portNumber, final Dependency dependency) {
+ this.pn = portNumber;
+ this.hn = hostName;
+ this.dependency = dependency;
+ }
+
+ public String toString() {
+ return "Number: " + pn + " String: " + hn + " Dependency: " + dependency;
+ }
+ }
+
+ @Test
+ public void thatParanamerHonorsNamedAnnotationFromJSR330() {
+
+ Properties properties = new Properties();
+ properties.put("portNumber", "1");
+ properties.put("hostName", "string");
+ properties.put("agentName", "agent0");
+ DefaultPicoContainer container = new DefaultPicoContainer(new PropertiesPicoContainer(properties));
+ container.as(Characteristics.USE_NAMES).addComponent(Dependant2.class);
+ container.as(Characteristics.USE_NAMES).addComponent(Dependency.class);
+ Dependant2 dependant = (Dependant2) container.getComponent(Dependant2.class);
+ assertEquals(1, dependant.pn);
+ assertEquals("string", dependant.hn);
+ }
+
+
+ public static class Dependant2 extends Dependant {
+ public Dependant2(@Named("hostName") String hn, @Named("portNumber") String pn, Dependency d) {
+ super(hn, Integer.parseInt(pn), d);
+ }
+ }
+
@Test public void testRepresentationOfContainerTree() {
Properties properties = new Properties();
properties.put("portNumber", 1);

----------

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.