/*
 * Copyright 2002-2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.context.annotation;

import org.junit.Test;
import org.springframework.context.annotation.configuration.StubSpecification;
import org.springframework.context.config.FeatureSpecification;

public class FeatureConfigurationClassTests {

	@Test(expected=FeatureMethodExecutionException.class)
	public void featureConfigurationClassesMustNotContainBeanAnnotatedMethods() {
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
		ctx.register(FeatureConfigWithBeanAnnotatedMethod.class);
		ctx.refresh();
	}

}


@FeatureConfiguration
class FeatureConfigWithBeanAnnotatedMethod {
	/**
	 * This is illegal use. @FeatureConfiguration classes cannot have @Bean methods.
	 */
	@Bean
	public TestBean testBean() {
		return new TestBean();
	}

	/**
	 * This will never get called. An exception will first be raised regarding the illegal @Bean method above.
	 */
	@Feature
	public FeatureSpecification feature() {
		return new StubSpecification();
	}
}
@@ -664,16 +664,156 @@
 ation;%0A%0A
+import static org.hamcrest.CoreMatchers.instanceOf;%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0A%0A
 import o
@@ -827,16 +827,16 @@
 t.Test;%0A
-
 import o
@@ -969,16 +969,67 @@
 ication;
+%0Aimport org.springframework.core.io.ResourceLoader;
 %0A%0Apublic
@@ -1369,16 +1369,300 @@
 ();%0A%09%7D%0A%0A
+%09@Test%0A%09public void featureMethodsMayAcceptResourceLoaderParameter() %7B%0A%09%09AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();%0A%09%09ctx.setDisplayName(%22enclosing app ctx%22);%0A%09%09ctx.register(FeatureMethodWithResourceLoaderParameter.class);%0A%09%09ctx.refresh();%0A%09%7D%0A%0A
 %7D%0A%0A%0A@Fea
@@ -2010,16 +2010,16 @@
 Feature%0A
-
 %09public 
@@ -2089,8 +2089,528 @@
 ();%0A%09%7D%0A%7D
+%0A%0A@FeatureConfiguration%0Aclass FeatureMethodWithResourceLoaderParameter %7B%0A%09@Feature%0A%09public FeatureSpecification feature(ResourceLoader rl) %7B%0A%09%09// prove that the injected ResourceLoader is actually the enclosing application context%0A%09%09Object target = ((EarlyBeanReferenceProxy)rl).dereferenceTargetBean();%0A%09%09assertThat(target, instanceOf(AnnotationConfigApplicationContext.class));%0A%09%09assertThat(((AnnotationConfigApplicationContext)target).getDisplayName(), is(%22enclosing app ctx%22));%0A%09%09return new StubSpecification();%0A%09%7D%0A%7D

Test injection of special types on @Feature methods