Browse Source

SpringJUnit4ClassRunnerAppCtxTests now verifies seamless support for using @Inject in addition to @Autowired, etc.

pull/23217/head
Sam Brannen 16 years ago
parent
commit
710ae3a9d2
  1. 1
      org.springframework.test/.classpath
  2. 1
      org.springframework.test/ivy.xml
  3. 6
      org.springframework.test/pom.xml
  4. 29
      org.springframework.test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerAppCtxTests.java
  5. 1
      org.springframework.test/test.iml

1
org.springframework.test/.classpath

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.web.portlet"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.web.servlet"/>
<classpathentry kind="var" path="IVY_CACHE/javax.activation/com.springsource.javax.activation/1.1.0/com.springsource.javax.activation-1.1.0.jar" sourcepath="/IVY_CACHE/javax.activation/com.springsource.javax.activation/1.1.0/com.springsource.javax.activation-sources-1.1.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.inject/com.springsource.javax.inject/0.9.0.PFD/com.springsource.javax.inject-0.9.0.PFD.jar" sourcepath="/IVY_CACHE/javax.inject/com.springsource.javax.inject/0.9.0.PFD/com.springsource.javax.inject-sources-0.9.0.PFD.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.persistence/com.springsource.javax.persistence/1.0.0/com.springsource.javax.persistence-1.0.0.jar" sourcepath="/IVY_CACHE/javax.persistence/com.springsource.javax.persistence/1.0.0/com.springsource.javax.persistence-sources-1.0.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.portlet/com.springsource.javax.portlet/2.0.0/com.springsource.javax.portlet-2.0.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-2.5.0.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-sources-2.5.0.jar"/>

1
org.springframework.test/ivy.xml

@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
<dependencies>
<dependency org="javax.activation" name="com.springsource.javax.activation" rev="1.1.0" conf="provided->compile"/>
<dependency org="javax.el" name="com.springsource.javax.el" rev="1.0.0" conf="provided->compile"/>
<dependency org="javax.inject" name="com.springsource.javax.inject" rev="0.9.0.PFD" conf="test->compile"/>
<dependency org="javax.persistence" name="com.springsource.javax.persistence" rev="1.0.0" conf="provided->compile"/>
<dependency org="javax.portlet" name="com.springsource.javax.portlet" rev="2.0.0" conf="provided->compile"/>
<dependency org="javax.servlet" name="com.springsource.javax.servlet" rev="2.5.0" conf="provided->compile"/>

6
org.springframework.test/pom.xml

@ -25,6 +25,12 @@ @@ -25,6 +25,12 @@
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>com.springsource.javax.inject</artifactId>
<version>0.9.0.PFD</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>

29
org.springframework.test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerAppCtxTests.java

@ -19,9 +19,11 @@ package org.springframework.test.context.junit4; @@ -19,9 +19,11 @@ package org.springframework.test.context.junit4;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -48,6 +50,7 @@ import org.springframework.test.context.support.GenericXmlContextLoader; @@ -48,6 +50,7 @@ import org.springframework.test.context.support.GenericXmlContextLoader;
* <ul>
* <li>{@link ContextConfiguration @ContextConfiguration}</li>
* <li>{@link Autowired @Autowired}</li>
* <li>{@link Inject @Inject}</li>
* <li>{@link Qualifier @Qualifier}</li>
* <li>{@link Resource @Resource}</li>
* <li>{@link ApplicationContextAware}</li>
@ -59,10 +62,12 @@ import org.springframework.test.context.support.GenericXmlContextLoader; @@ -59,10 +62,12 @@ import org.springframework.test.context.support.GenericXmlContextLoader;
* {@link ContextConfiguration#locations() locations} are explicitly declared
* and since the {@link ContextConfiguration#loader() ContextLoader} is left set
* to the default value of {@link GenericXmlContextLoader}, this test class's
* dependencies will be injected via {@link Autowired @Autowired} and
* {@link Resource @Resource} from beans defined in the
* {@link ApplicationContext} loaded from the default classpath resource:
* <code>&quot;/org/springframework/test/context/junit/SpringJUnit4ClassRunnerAppCtxTests-context.xml&quot;</code>.
* dependencies will be injected via {@link Autowired @Autowired},
* {@link Inject @Inject}, and {@link Resource @Resource} from beans defined in
* the {@link ApplicationContext} loaded from the default classpath resource:
*
* <code>&quot;/org/springframework/test/context/junit/SpringJUnit4ClassRunnerAppCtxTests-context.xml&quot;</code>
* .
* </p>
*
* @author Sam Brannen
@ -93,12 +98,15 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa @@ -93,12 +98,15 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa
private Employee employee;
@Autowired
private Pet pet;
private Pet autowiredPet;
@Inject
private Pet injectedPet;
@Autowired(required = false)
protected Long nonrequiredLong;
@Resource()
@Resource
protected String foo;
protected String bar;
@ -153,11 +161,14 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa @@ -153,11 +161,14 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa
}
@Test
public final void verifyAnnotationAutowiredFields() {
public final void verifyAnnotationAutowiredAndInjectedFields() {
assertNull("The nonrequiredLong field should NOT have been autowired.", this.nonrequiredLong);
assertEquals("The quux field should have been autowired via @Autowired and @Qualifier.", "Quux", this.quux);
assertNotNull("The pet field should have been autowired.", this.pet);
assertEquals("Fido", this.pet.getName());
assertNotNull("The pet field should have been autowired.", this.autowiredPet);
assertNotNull("The pet field should have been injected.", this.injectedPet);
assertEquals("Fido", this.autowiredPet.getName());
assertEquals("Fido", this.injectedPet.getName());
assertSame("@Autowired and @Inject pet should be the same object.", this.autowiredPet, this.injectedPet);
}
@Test

1
org.springframework.test/test.iml

@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
<orderEntry type="library" name="Commons Logging" level="project" />
<orderEntry type="library" name="EasyMock" level="project" />
<orderEntry type="library" name="javax.el" level="project" />
<orderEntry type="library" name="javax.inject" level="project" />
<orderEntry type="library" name="JUnit" level="project" />
<orderEntry type="module-library">
<library>

Loading…
Cancel
Save