|
|
|
|
@ -102,6 +102,46 @@ public class ConditionalOnSingleCandidateTests {
@@ -102,6 +102,46 @@ public class ConditionalOnSingleCandidateTests {
|
|
|
|
|
parent.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void singleCandidateInAncestorsOneCandidateInCurrent() { |
|
|
|
|
load(); |
|
|
|
|
AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); |
|
|
|
|
child.register(FooConfiguration.class, |
|
|
|
|
OnBeanSingleCandidateInAncestorsConfiguration.class); |
|
|
|
|
child.setParent(this.context); |
|
|
|
|
child.refresh(); |
|
|
|
|
assertThat(child.containsBean("baz")).isFalse(); |
|
|
|
|
child.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void singleCandidateInAncestorsOneCandidateInParent() { |
|
|
|
|
load(FooConfiguration.class); |
|
|
|
|
AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); |
|
|
|
|
child.register(OnBeanSingleCandidateInAncestorsConfiguration.class); |
|
|
|
|
child.setParent(this.context); |
|
|
|
|
child.refresh(); |
|
|
|
|
assertThat(child.containsBean("baz")).isTrue(); |
|
|
|
|
assertThat(child.getBean("baz")).isEqualTo("foo"); |
|
|
|
|
child.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void singleCandidateInAncestorsOneCandidateInGrandparent() { |
|
|
|
|
load(FooConfiguration.class); |
|
|
|
|
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(); |
|
|
|
|
parent.setParent(this.context); |
|
|
|
|
parent.refresh(); |
|
|
|
|
AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); |
|
|
|
|
child.register(OnBeanSingleCandidateInAncestorsConfiguration.class); |
|
|
|
|
child.setParent(parent); |
|
|
|
|
child.refresh(); |
|
|
|
|
assertThat(child.containsBean("baz")).isTrue(); |
|
|
|
|
assertThat(child.getBean("baz")).isEqualTo("foo"); |
|
|
|
|
child.close(); |
|
|
|
|
parent.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void singleCandidateMultipleCandidates() { |
|
|
|
|
load(FooConfiguration.class, BarConfiguration.class, |
|
|
|
|
@ -176,6 +216,7 @@ public class ConditionalOnSingleCandidateTests {
@@ -176,6 +216,7 @@ public class ConditionalOnSingleCandidateTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
|
@Configuration |
|
|
|
|
@ConditionalOnSingleCandidate(value = String.class, search = SearchStrategy.PARENTS) |
|
|
|
|
protected static class OnBeanSingleCandidateInParentsConfiguration { |
|
|
|
|
@ -187,6 +228,17 @@ public class ConditionalOnSingleCandidateTests {
@@ -187,6 +228,17 @@ public class ConditionalOnSingleCandidateTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
@ConditionalOnSingleCandidate(value = String.class, search = SearchStrategy.ANCESTORS) |
|
|
|
|
protected static class OnBeanSingleCandidateInAncestorsConfiguration { |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public String baz(String s) { |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
@ConditionalOnSingleCandidate(value = String.class, type = "java.lang.String") |
|
|
|
|
protected static class OnBeanSingleCandidateTwoTypesConfiguration { |
|
|
|
|
|