[SPR-6918] Now verifying support for @Value in conjunction with the Spring TestContext Framework.
This commit is contained in:
parent
0543036ec9
commit
69cbadf7e9
|
|
@ -35,6 +35,7 @@ import org.springframework.beans.factory.BeanNameAware;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
@ -53,6 +54,7 @@ import org.springframework.test.context.support.GenericXmlContextLoader;
|
||||||
* <li>{@link Autowired @Autowired}</li>
|
* <li>{@link Autowired @Autowired}</li>
|
||||||
* <li>{@link Qualifier @Qualifier}</li>
|
* <li>{@link Qualifier @Qualifier}</li>
|
||||||
* <li>{@link Resource @Resource}</li>
|
* <li>{@link Resource @Resource}</li>
|
||||||
|
* <li>{@link Value @Value}</li>
|
||||||
* <li>{@link Inject @Inject}</li>
|
* <li>{@link Inject @Inject}</li>
|
||||||
* <li>{@link Named @Named}</li>
|
* <li>{@link Named @Named}</li>
|
||||||
* <li>{@link ApplicationContextAware}</li>
|
* <li>{@link ApplicationContextAware}</li>
|
||||||
|
|
@ -113,6 +115,16 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa
|
||||||
|
|
||||||
protected String bar;
|
protected String bar;
|
||||||
|
|
||||||
|
@Value("enigma")
|
||||||
|
private String literalFieldValue;
|
||||||
|
|
||||||
|
@Value("#{2 == (1+1)}")
|
||||||
|
private Boolean spelFieldValue;
|
||||||
|
|
||||||
|
private String literalParameterValue;
|
||||||
|
|
||||||
|
private Boolean spelParameterValue;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("quux")
|
@Qualifier("quux")
|
||||||
protected String quux;
|
protected String quux;
|
||||||
|
|
@ -146,6 +158,16 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa
|
||||||
this.bar = bar;
|
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
|
@Test
|
||||||
|
|
@ -187,6 +209,22 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa
|
||||||
assertEquals("John Smith", this.employee.getName());
|
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
|
@Test
|
||||||
public final void verifyResourceAnnotationInjectedFields() {
|
public final void verifyResourceAnnotationInjectedFields() {
|
||||||
assertEquals("The foo field should have been injected via @Resource.", "Foo", this.foo);
|
assertEquals("The foo field should have been injected via @Resource.", "Foo", this.foo);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue