From 704b229cc7448b9f53adb3271cd18ba9b1677703 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Sat, 12 Mar 2011 12:24:20 +0000 Subject: [PATCH] Test injection of Environment on @Feature methods Issue: SPR-7975 --- .../annotation/FeatureConfigurationClassTests.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation/FeatureConfigurationClassTests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/FeatureConfigurationClassTests.java index 195db2436fb..e2610ac3b06 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/annotation/FeatureConfigurationClassTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/FeatureConfigurationClassTests.java @@ -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 { 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 { @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));