Commit 32bd845a authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '2.2.x'

Closes gh-20116
parents 85eb279b b4d118e0
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -387,7 +387,7 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat ...@@ -387,7 +387,7 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat
private final ClassLoader classLoader; private final ClassLoader classLoader;
private final Class<?> annotationType; private final Class<? extends Annotation> annotationType;
private final Set<String> names; private final Set<String> names;
...@@ -581,11 +581,11 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat ...@@ -581,11 +581,11 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat
} }
ConditionMessage.Builder message() { ConditionMessage.Builder message() {
return ConditionMessage.forCondition(ConditionalOnBean.class, this); return ConditionMessage.forCondition(this.annotationType, this);
} }
ConditionMessage.Builder message(ConditionMessage message) { ConditionMessage.Builder message(ConditionMessage message) {
return message.andCondition(ConditionalOnBean.class, this); return message.andCondition(this.annotationType, this);
} }
@Override @Override
......
...@@ -21,6 +21,7 @@ import java.lang.annotation.ElementType; ...@@ -21,6 +21,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.function.Consumer; import java.util.function.Consumer;
...@@ -29,6 +30,7 @@ import org.junit.jupiter.api.Test; ...@@ -29,6 +30,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
...@@ -134,6 +136,17 @@ class ConditionalOnBeanTests { ...@@ -134,6 +136,17 @@ class ConditionalOnBeanTests {
assertThat(context.getBean("bar")).isEqualTo("bar"); assertThat(context.getBean("bar")).isEqualTo("bar");
} }
@Test
void onBeanConditionOutputShouldNotContainConditionalOnMissingBeanClassInMessage() {
this.contextRunner.withUserConfiguration(OnBeanNameConfiguration.class).run((context) -> {
Collection<ConditionAndOutcomes> conditionAndOutcomes = ConditionEvaluationReport
.get(context.getSourceApplicationContext().getBeanFactory()).getConditionAndOutcomesBySource()
.values();
String message = conditionAndOutcomes.iterator().next().iterator().next().getOutcome().getMessage();
assertThat(message).doesNotContain("@ConditionalOnMissingBean");
});
}
@Test @Test
void conditionEvaluationConsidersChangeInTypeWhenBeanIsOverridden() { void conditionEvaluationConsidersChangeInTypeWhenBeanIsOverridden() {
this.contextRunner.withAllowBeanDefinitionOverriding(true).withUserConfiguration(OriginalDefinition.class, this.contextRunner.withAllowBeanDefinitionOverriding(true).withUserConfiguration(OriginalDefinition.class,
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -21,6 +21,7 @@ import java.lang.annotation.ElementType; ...@@ -21,6 +21,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.function.Consumer; import java.util.function.Consumer;
...@@ -136,6 +137,17 @@ public class ConditionalOnMissingBeanTests { ...@@ -136,6 +137,17 @@ public class ConditionalOnMissingBeanTests {
}); });
} }
@Test
void testOnMissingBeanConditionOutputShouldNotContainConditionalOnBeanClassInMessage() {
this.contextRunner.withUserConfiguration(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");
});
}
@Test @Test
void testOnMissingBeanConditionWithFactoryBean() { void testOnMissingBeanConditionWithFactoryBean() {
this.contextRunner this.contextRunner
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment