Add some test cases and comments

In response to gh-352
pull/355/head
Dave Syer 11 years ago
parent e4376bc4a6
commit fc4aabde75

@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.condition; package org.springframework.boot.autoconfigure.condition;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
@ -109,6 +110,25 @@ public class ConditionalOnMissingBeanTests {
assertEquals("foo", this.context.getBean("foo")); assertEquals("foo", this.context.getBean("foo"));
} }
@Test
@Ignore("This will never work - you need to use XML for FactoryBeans, or else call getObject() inside the @Bean method")
public void testOnMissingBeanConditionWithFactoryBean() {
this.context.register(ExampleBeanAndFactoryBeanConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
// There should be only one
this.context.getBean(ExampleBean.class);
}
@Test
public void testOnMissingBeanConditionWithFactoryBeanInXml() {
this.context.register(ConfigurationWithFactoryBean.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
// There should be only one
this.context.getBean(ExampleBean.class);
}
@Configuration @Configuration
@ConditionalOnMissingBean(name = "foo") @ConditionalOnMissingBean(name = "foo")
protected static class OnBeanNameConfiguration { protected static class OnBeanNameConfiguration {
@ -118,6 +138,21 @@ public class ConditionalOnMissingBeanTests {
} }
} }
@Configuration
protected static class ExampleBeanAndFactoryBeanConfiguration {
@Bean
public FactoryBean<ExampleBean> exampleBeanFactoryBean() {
return new ExampleFactoryBean("foo");
}
@Bean
@ConditionalOnMissingBean(ExampleBean.class)
public ExampleBean createExampleBean() {
return new ExampleBean();
}
}
@Configuration @Configuration
@ConditionalOnMissingBean(annotation = EnableScheduling.class) @ConditionalOnMissingBean(annotation = EnableScheduling.class)
protected static class OnAnnotationConfiguration { protected static class OnAnnotationConfiguration {

Loading…
Cancel
Save