|
|
@ -64,6 +64,46 @@ public class ConditionalOnSingleCandidateTests {
|
|
|
|
assertEquals("foo", this.context.getBean("baz"));
|
|
|
|
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
|
|
|
|
@Test
|
|
|
|
public void singleCandidateMultipleCandidates() {
|
|
|
|
public void singleCandidateMultipleCandidates() {
|
|
|
|
load(FooConfiguration.class, BarConfiguration.class,
|
|
|
|
load(FooConfiguration.class, BarConfiguration.class,
|
|
|
@ -121,7 +161,9 @@ public class ConditionalOnSingleCandidateTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void load(Class<?>... classes) {
|
|
|
|
private void load(Class<?>... classes) {
|
|
|
|
this.context.register(classes);
|
|
|
|
if (classes.length > 0) {
|
|
|
|
|
|
|
|
this.context.register(classes);
|
|
|
|
|
|
|
|
}
|
|
|
|
this.context.refresh();
|
|
|
|
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
|
|
|
|
@Configuration
|
|
|
|
@ConditionalOnSingleCandidate(value = String.class, type = "java.lang.String")
|
|
|
|
@ConditionalOnSingleCandidate(value = String.class, type = "java.lang.String")
|
|
|
|
protected static class OnBeanSingleCandidateTwoTypesConfiguration {
|
|
|
|
protected static class OnBeanSingleCandidateTwoTypesConfiguration {
|
|
|
|