From 6b616956fc1a5d19f6f2f74131c83a33ad29391b Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Fri, 11 Mar 2011 12:40:51 +0000 Subject: [PATCH] Test injection of special types on @Feature methods Prove that injection of special container types such as ResourceLoader, BeanFactory, etc already works with the current implementation of @Feature methods. Issue: SPR-7975 git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4082 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../FeatureConfigurationClassTests.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 a7831d0eaa3..195db2436fb 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 @@ -16,9 +16,14 @@ package org.springframework.context.annotation; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +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.io.ResourceLoader; public class FeatureConfigurationClassTests { @@ -29,6 +34,14 @@ public class FeatureConfigurationClassTests { ctx.refresh(); } + @Test + public void featureMethodsMayAcceptResourceLoaderParameter() { + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); + ctx.setDisplayName("enclosing app ctx"); + ctx.register(FeatureMethodWithResourceLoaderParameter.class); + ctx.refresh(); + } + } @@ -49,4 +62,16 @@ class FeatureConfigWithBeanAnnotatedMethod { public FeatureSpecification feature() { return new StubSpecification(); } +} + +@FeatureConfiguration +class FeatureMethodWithResourceLoaderParameter { + @Feature + public FeatureSpecification feature(ResourceLoader rl) { + // prove that the injected ResourceLoader is actually the enclosing application context + Object target = ((EarlyBeanReferenceProxy)rl).dereferenceTargetBean(); + assertThat(target, instanceOf(AnnotationConfigApplicationContext.class)); + assertThat(((AnnotationConfigApplicationContext)target).getDisplayName(), is("enclosing app ctx")); + return new StubSpecification(); + } } \ No newline at end of file