Skip to content

Commit fc4aabd

Browse files
author
Dave Syer
committed
Add some test cases and comments
In response to spring-projectsgh-352
1 parent e4376bc commit fc4aabd

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Diff for: spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java

+35
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.condition;
1818

19+
import org.junit.Ignore;
1920
import org.junit.Test;
2021
import org.springframework.beans.factory.FactoryBean;
2122
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
@@ -109,6 +110,25 @@ public void testAnnotationOnMissingBeanConditionWithEagerFactoryBean() {
109110
assertEquals("foo", this.context.getBean("foo"));
110111
}
111112

113+
@Test
114+
@Ignore("This will never work - you need to use XML for FactoryBeans, or else call getObject() inside the @Bean method")
115+
public void testOnMissingBeanConditionWithFactoryBean() {
116+
this.context.register(ExampleBeanAndFactoryBeanConfiguration.class,
117+
PropertyPlaceholderAutoConfiguration.class);
118+
this.context.refresh();
119+
// There should be only one
120+
this.context.getBean(ExampleBean.class);
121+
}
122+
123+
@Test
124+
public void testOnMissingBeanConditionWithFactoryBeanInXml() {
125+
this.context.register(ConfigurationWithFactoryBean.class,
126+
PropertyPlaceholderAutoConfiguration.class);
127+
this.context.refresh();
128+
// There should be only one
129+
this.context.getBean(ExampleBean.class);
130+
}
131+
112132
@Configuration
113133
@ConditionalOnMissingBean(name = "foo")
114134
protected static class OnBeanNameConfiguration {
@@ -118,6 +138,21 @@ public String bar() {
118138
}
119139
}
120140

141+
@Configuration
142+
protected static class ExampleBeanAndFactoryBeanConfiguration {
143+
144+
@Bean
145+
public FactoryBean<ExampleBean> exampleBeanFactoryBean() {
146+
return new ExampleFactoryBean("foo");
147+
}
148+
149+
@Bean
150+
@ConditionalOnMissingBean(ExampleBean.class)
151+
public ExampleBean createExampleBean() {
152+
return new ExampleBean();
153+
}
154+
}
155+
121156
@Configuration
122157
@ConditionalOnMissingBean(annotation = EnableScheduling.class)
123158
protected static class OnAnnotationConfiguration {

0 commit comments

Comments
 (0)