|
|
|
@ -64,6 +64,46 @@ public class ConditionalOnSingleCandidateTests {
|
|
|
|
|
assertEquals("foo", this.context.getBean("baz"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void singleCandidateInParentsOneCandidateInCurrent() {
|
|
|
|
|
load();
|
|
|
|
|
AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
|
|
|
|
|
child.register(FooConfiguration.class,
|
|
|
|
|
OnBeanSingleCandidateInParentsConfiguration.class);
|
|
|
|
|
child.setParent(this.context);
|
|
|
|
|
child.refresh();
|
|
|
|
|
assertFalse(child.containsBean("baz"));
|
|
|
|
|
child.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void singleCandidateInParentsOneCandidateInParent() {
|
|
|
|
|
load(FooConfiguration.class);
|
|
|
|
|
AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
|
|
|
|
|
child.register(OnBeanSingleCandidateInParentsConfiguration.class);
|
|
|
|
|
child.setParent(this.context);
|
|
|
|
|
child.refresh();
|
|
|
|
|
assertTrue(child.containsBean("baz"));
|
|
|
|
|
assertEquals("foo", child.getBean("baz"));
|
|
|
|
|
child.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void singleCandidateInParentsOneCandidateInGrandparent() {
|
|
|
|
|
load(FooConfiguration.class);
|
|
|
|
|
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
|
|
|
|
parent.setParent(this.context);
|
|
|
|
|
parent.refresh();
|
|
|
|
|
AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
|
|
|
|
|
child.register(OnBeanSingleCandidateInParentsConfiguration.class);
|
|
|
|
|
child.setParent(parent);
|
|
|
|
|
child.refresh();
|
|
|
|
|
assertTrue(child.containsBean("baz"));
|
|
|
|
|
assertEquals("foo", child.getBean("baz"));
|
|
|
|
|
child.close();
|
|
|
|
|
parent.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void singleCandidateMultipleCandidates() {
|
|
|
|
|
load(FooConfiguration.class, BarConfiguration.class,
|
|
|
|
@ -121,7 +161,9 @@ public class ConditionalOnSingleCandidateTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void load(Class<?>... classes) {
|
|
|
|
|
this.context.register(classes);
|
|
|
|
|
if (classes.length > 0) {
|
|
|
|
|
this.context.register(classes);
|
|
|
|
|
}
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -136,6 +178,17 @@ public class ConditionalOnSingleCandidateTests {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnSingleCandidate(value = String.class, search = SearchStrategy.PARENTS)
|
|
|
|
|
protected static class OnBeanSingleCandidateInParentsConfiguration {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public String baz(String s) {
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnSingleCandidate(value = String.class, type = "java.lang.String")
|
|
|
|
|
protected static class OnBeanSingleCandidateTwoTypesConfiguration {
|
|
|
|
|