Browse Source

Test injection of Environment on @Feature methods

Issue: SPR-7975
pull/7/head
Chris Beams 14 years ago
parent
commit
704b229cc7
  1. 8
      org.springframework.context/src/test/java/org/springframework/context/annotation/FeatureConfigurationClassTests.java

8
org.springframework.context/src/test/java/org/springframework/context/annotation/FeatureConfigurationClassTests.java

@ -23,7 +23,9 @@ import static org.junit.Assert.assertThat; @@ -23,7 +23,9 @@ import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.springframework.context.annotation.configuration.StubSpecification;
import org.springframework.context.config.FeatureSpecification;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.mock.env.MockEnvironment;
public class FeatureConfigurationClassTests {
@ -38,6 +40,7 @@ public class FeatureConfigurationClassTests { @@ -38,6 +40,7 @@ public class FeatureConfigurationClassTests {
public void featureMethodsMayAcceptResourceLoaderParameter() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setDisplayName("enclosing app ctx");
ctx.setEnvironment(new MockEnvironment().withProperty("foo", "bar"));
ctx.register(FeatureMethodWithResourceLoaderParameter.class);
ctx.refresh();
}
@ -67,7 +70,10 @@ class FeatureConfigWithBeanAnnotatedMethod { @@ -67,7 +70,10 @@ class FeatureConfigWithBeanAnnotatedMethod {
@FeatureConfiguration
class FeatureMethodWithResourceLoaderParameter {
@Feature
public FeatureSpecification feature(ResourceLoader rl) {
public FeatureSpecification feature(ResourceLoader rl,
Environment e) {
// prove that the injected Environment is that of the enclosing app context
assertThat(e.getProperty("foo"), is("bar"));
// prove that the injected ResourceLoader is actually the enclosing application context
Object target = ((EarlyBeanReferenceProxy)rl).dereferenceTargetBean();
assertThat(target, instanceOf(AnnotationConfigApplicationContext.class));

Loading…
Cancel
Save