Skip to content

Commit 710ae3a

Browse files
committed
SpringJUnit4ClassRunnerAppCtxTests now verifies seamless support for using @Inject in addition to @Autowired, etc.
1 parent 0a843e6 commit 710ae3a

5 files changed

Lines changed: 30 additions & 10 deletions

File tree

org.springframework.test/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.web.portlet"/>
1616
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.web.servlet"/>
1717
<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"/>
18+
<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"/>
1819
<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"/>
1920
<classpathentry kind="var" path="IVY_CACHE/javax.portlet/com.springsource.javax.portlet/2.0.0/com.springsource.javax.portlet-2.0.0.jar"/>
2021
<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"/>

org.springframework.test/ivy.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<dependencies>
2222
<dependency org="javax.activation" name="com.springsource.javax.activation" rev="1.1.0" conf="provided->compile"/>
2323
<dependency org="javax.el" name="com.springsource.javax.el" rev="1.0.0" conf="provided->compile"/>
24+
<dependency org="javax.inject" name="com.springsource.javax.inject" rev="0.9.0.PFD" conf="test->compile"/>
2425
<dependency org="javax.persistence" name="com.springsource.javax.persistence" rev="1.0.0" conf="provided->compile"/>
2526
<dependency org="javax.portlet" name="com.springsource.javax.portlet" rev="2.0.0" conf="provided->compile"/>
2627
<dependency org="javax.servlet" name="com.springsource.javax.servlet" rev="2.5.0" conf="provided->compile"/>

org.springframework.test/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
<version>1.0</version>
2626
<scope>provided</scope>
2727
</dependency>
28+
<dependency>
29+
<groupId>javax.inject</groupId>
30+
<artifactId>com.springsource.javax.inject</artifactId>
31+
<version>0.9.0.PFD</version>
32+
<scope>test</scope>
33+
</dependency>
2834
<dependency>
2935
<groupId>javax.persistence</groupId>
3036
<artifactId>persistence-api</artifactId>

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNotNull;
2121
import static org.junit.Assert.assertNull;
22+
import static org.junit.Assert.assertSame;
2223
import static org.junit.Assert.assertTrue;
2324

2425
import javax.annotation.Resource;
26+
import javax.inject.Inject;
2527

2628
import org.junit.Test;
2729
import org.junit.runner.RunWith;
@@ -48,6 +50,7 @@
4850
* <ul>
4951
* <li>{@link ContextConfiguration @ContextConfiguration}</li>
5052
* <li>{@link Autowired @Autowired}</li>
53+
* <li>{@link Inject @Inject}</li>
5154
* <li>{@link Qualifier @Qualifier}</li>
5255
* <li>{@link Resource @Resource}</li>
5356
* <li>{@link ApplicationContextAware}</li>
@@ -59,10 +62,12 @@
5962
* {@link ContextConfiguration#locations() locations} are explicitly declared
6063
* and since the {@link ContextConfiguration#loader() ContextLoader} is left set
6164
* to the default value of {@link GenericXmlContextLoader}, this test class's
62-
* dependencies will be injected via {@link Autowired @Autowired} and
63-
* {@link Resource @Resource} from beans defined in the
64-
* {@link ApplicationContext} loaded from the default classpath resource:
65-
* <code>&quot;/org/springframework/test/context/junit/SpringJUnit4ClassRunnerAppCtxTests-context.xml&quot;</code>.
65+
* dependencies will be injected via {@link Autowired @Autowired},
66+
* {@link Inject @Inject}, and {@link Resource @Resource} from beans defined in
67+
* the {@link ApplicationContext} loaded from the default classpath resource:
68+
*
69+
* <code>&quot;/org/springframework/test/context/junit/SpringJUnit4ClassRunnerAppCtxTests-context.xml&quot;</code>
70+
* .
6671
* </p>
6772
*
6873
* @author Sam Brannen
@@ -93,12 +98,15 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa
9398
private Employee employee;
9499

95100
@Autowired
96-
private Pet pet;
101+
private Pet autowiredPet;
102+
103+
@Inject
104+
private Pet injectedPet;
97105

98106
@Autowired(required = false)
99107
protected Long nonrequiredLong;
100108

101-
@Resource()
109+
@Resource
102110
protected String foo;
103111

104112
protected String bar;
@@ -153,11 +161,14 @@ public final void verifyBeanNameSet() {
153161
}
154162

155163
@Test
156-
public final void verifyAnnotationAutowiredFields() {
164+
public final void verifyAnnotationAutowiredAndInjectedFields() {
157165
assertNull("The nonrequiredLong field should NOT have been autowired.", this.nonrequiredLong);
158166
assertEquals("The quux field should have been autowired via @Autowired and @Qualifier.", "Quux", this.quux);
159-
assertNotNull("The pet field should have been autowired.", this.pet);
160-
assertEquals("Fido", this.pet.getName());
167+
assertNotNull("The pet field should have been autowired.", this.autowiredPet);
168+
assertNotNull("The pet field should have been injected.", this.injectedPet);
169+
assertEquals("Fido", this.autowiredPet.getName());
170+
assertEquals("Fido", this.injectedPet.getName());
171+
assertSame("@Autowired and @Inject pet should be the same object.", this.autowiredPet, this.injectedPet);
161172
}
162173

163174
@Test
@@ -176,4 +187,4 @@ public final void verifyResourceAnnotationWiredMethods() {
176187
assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar);
177188
}
178189

179-
}
190+
}

org.springframework.test/test.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<orderEntry type="library" name="Commons Logging" level="project" />
2525
<orderEntry type="library" name="EasyMock" level="project" />
2626
<orderEntry type="library" name="javax.el" level="project" />
27+
<orderEntry type="library" name="javax.inject" level="project" />
2728
<orderEntry type="library" name="JUnit" level="project" />
2829
<orderEntry type="module-library">
2930
<library>

0 commit comments

Comments
 (0)