Fix condition source in OnBeanCondition

See gh-19948
pull/20222/head
Jorge Cordoba 5 years ago committed by Stephane Nicoll
parent d485708f68
commit 547fc30ead

@ -67,6 +67,7 @@ import org.springframework.util.StringUtils;
* @author Jakub Kubrynski
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Jorge Cordoba
* @see ConditionalOnBean
* @see ConditionalOnMissingBean
* @see ConditionalOnSingleCandidate
@ -387,7 +388,7 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat
private final ClassLoader classLoader;
private final Class<?> annotationType;
private final Class<? extends Annotation> annotationType;
private final Set<String> names;
@ -581,11 +582,11 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat
}
ConditionMessage.Builder message() {
return ConditionMessage.forCondition(ConditionalOnBean.class, this);
return ConditionMessage.forCondition(this.annotationType, this);
}
ConditionMessage.Builder message(ConditionMessage message) {
return message.andCondition(ConditionalOnBean.class, this);
return message.andCondition(this.annotationType, this);
}
@Override

@ -21,6 +21,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Collection;
import java.util.Date;
import java.util.function.Consumer;
@ -57,6 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Phillip Webb
* @author Jakub Kubrynski
* @author Andy Wilkinson
* @author Jorge Cordoba
*/
@SuppressWarnings("resource")
public class ConditionalOnMissingBeanTests {
@ -135,6 +137,16 @@ public class ConditionalOnMissingBeanTests {
assertThat(context.getBean("foo")).isEqualTo("foo");
});
}
@Test
void testOnMissingBeanConditionOutputShouldNotContainConditionalOnBeanClassInMessage() {
this.contextRunner.withUserConfiguration(ConditionalOnMissingBeanTests.OnBeanNameConfiguration.class).run((context) -> {
Collection<ConditionEvaluationReport.ConditionAndOutcomes> conditionAndOutcomes = ConditionEvaluationReport
.get(context.getSourceApplicationContext().getBeanFactory()).getConditionAndOutcomesBySource()
.values();
String message = conditionAndOutcomes.iterator().next().iterator().next().getOutcome().getMessage();
assertThat(message).doesNotContain("@ConditionalOnBean (names: foo; SearchStrategy: all) did not find any beans");
});
}
@Test
void testOnMissingBeanConditionWithFactoryBean() {

Loading…
Cancel
Save