Skip to content

Commit 66809c6

Browse files
committed
Polish "Fix condition source in OnBeanCondition"
See gh-19948
1 parent 547fc30 commit 66809c6

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,7 +67,6 @@
6767
* @author Jakub Kubrynski
6868
* @author Stephane Nicoll
6969
* @author Andy Wilkinson
70-
* @author Jorge Cordoba
7170
* @see ConditionalOnBean
7271
* @see ConditionalOnMissingBean
7372
* @see ConditionalOnSingleCandidate

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnBeanTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.lang.annotation.Retention;
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
24+
import java.util.Collection;
2425
import java.util.Date;
2526
import java.util.function.Consumer;
2627

@@ -29,6 +30,7 @@
2930
import org.springframework.beans.factory.FactoryBean;
3031
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
3132
import org.springframework.beans.factory.support.RootBeanDefinition;
33+
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes;
3234
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
3335
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3436
import org.springframework.context.ConfigurableApplicationContext;
@@ -134,6 +136,17 @@ private void hasBarBean(AssertableApplicationContext context) {
134136
assertThat(context.getBean("bar")).isEqualTo("bar");
135137
}
136138

139+
@Test
140+
void onBeanConditionOutputShouldNotContainConditionalOnMissingBeanClassInMessage() {
141+
this.contextRunner.withUserConfiguration(OnBeanNameConfiguration.class).run((context) -> {
142+
Collection<ConditionAndOutcomes> conditionAndOutcomes = ConditionEvaluationReport
143+
.get(context.getSourceApplicationContext().getBeanFactory()).getConditionAndOutcomesBySource()
144+
.values();
145+
String message = conditionAndOutcomes.iterator().next().iterator().next().getOutcome().getMessage();
146+
assertThat(message).doesNotContain("@ConditionalOnMissingBean");
147+
});
148+
}
149+
137150
@Test
138151
void conditionEvaluationConsidersChangeInTypeWhenBeanIsOverridden() {
139152
this.contextRunner.withUserConfiguration(OriginalDefinition.class, OverridingDefinition.class,

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,7 +58,6 @@
5858
* @author Phillip Webb
5959
* @author Jakub Kubrynski
6060
* @author Andy Wilkinson
61-
* @author Jorge Cordoba
6261
*/
6362
@SuppressWarnings("resource")
6463
public class ConditionalOnMissingBeanTests {
@@ -137,14 +136,15 @@ void testAnnotationOnMissingBeanConditionWithEagerFactoryBean() {
137136
assertThat(context.getBean("foo")).isEqualTo("foo");
138137
});
139138
}
139+
140140
@Test
141141
void testOnMissingBeanConditionOutputShouldNotContainConditionalOnBeanClassInMessage() {
142-
this.contextRunner.withUserConfiguration(ConditionalOnMissingBeanTests.OnBeanNameConfiguration.class).run((context) -> {
142+
this.contextRunner.withUserConfiguration(OnBeanNameConfiguration.class).run((context) -> {
143143
Collection<ConditionEvaluationReport.ConditionAndOutcomes> conditionAndOutcomes = ConditionEvaluationReport
144144
.get(context.getSourceApplicationContext().getBeanFactory()).getConditionAndOutcomesBySource()
145145
.values();
146146
String message = conditionAndOutcomes.iterator().next().iterator().next().getOutcome().getMessage();
147-
assertThat(message).doesNotContain("@ConditionalOnBean (names: foo; SearchStrategy: all) did not find any beans");
147+
assertThat(message).doesNotContain("@ConditionalOnBean");
148148
});
149149
}
150150

0 commit comments

Comments
 (0)