diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerAppCtxTests.java b/org.springframework.test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerAppCtxTests.java index 1f8f95a4a7d..af1389b879d 100644 --- a/org.springframework.test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerAppCtxTests.java +++ b/org.springframework.test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerAppCtxTests.java @@ -35,6 +35,7 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.test.context.ContextConfiguration; @@ -53,6 +54,7 @@ import org.springframework.test.context.support.GenericXmlContextLoader; *
  • {@link Autowired @Autowired}
  • *
  • {@link Qualifier @Qualifier}
  • *
  • {@link Resource @Resource}
  • + *
  • {@link Value @Value}
  • *
  • {@link Inject @Inject}
  • *
  • {@link Named @Named}
  • *
  • {@link ApplicationContextAware}
  • @@ -113,6 +115,16 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa protected String bar; + @Value("enigma") + private String literalFieldValue; + + @Value("#{2 == (1+1)}") + private Boolean spelFieldValue; + + private String literalParameterValue; + + private Boolean spelParameterValue; + @Autowired @Qualifier("quux") protected String quux; @@ -146,6 +158,16 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa this.bar = bar; } + @Autowired + public void setLiteralParameterValue(@Value("enigma") String literalParameterValue) { + this.literalParameterValue = literalParameterValue; + } + + @Autowired + public void setSpelParameterValue(@Value("#{2 == (1+1)}") Boolean spelParameterValue) { + this.spelParameterValue = spelParameterValue; + } + // ------------------------------------------------------------------------| @Test @@ -187,6 +209,22 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa assertEquals("John Smith", this.employee.getName()); } + @Test + public final void verifyAutowiredAtValueFields() { + assertNotNull("Literal @Value field should have been autowired", this.literalFieldValue); + assertNotNull("SpEL @Value field should have been autowired.", this.spelFieldValue); + assertEquals("enigma", this.literalFieldValue); + assertEquals(Boolean.TRUE, this.spelFieldValue); + } + + @Test + public final void verifyAutowiredAtValueMethods() { + assertNotNull("Literal @Value method parameter should have been autowired.", this.literalParameterValue); + assertNotNull("SpEL @Value method parameter should have been autowired.", this.spelParameterValue); + assertEquals("enigma", this.literalParameterValue); + assertEquals(Boolean.TRUE, this.spelParameterValue); + } + @Test public final void verifyResourceAnnotationInjectedFields() { assertEquals("The foo field should have been injected via @Resource.", "Foo", this.foo);