Rename BeanOverrideStrategy enum constants

Closes gh-33701
This commit is contained in:
Sam Brannen
2024-10-15 18:19:37 +02:00
parent 7ea43bb252
commit 67cb3c77ec
22 changed files with 95 additions and 96 deletions

View File

@@ -83,7 +83,7 @@ class BeanOverrideBeanFactoryPostProcessorTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("Unable to override bean: there is no bean definition " +
.withMessage("Unable to override bean: there is no bean " +
"to replace with name [descriptionBean] and type [java.lang.String].");
}
@@ -94,7 +94,7 @@ class BeanOverrideBeanFactoryPostProcessorTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("Unable to override bean: there is no bean definition " +
.withMessage("Unable to override bean: there is no bean " +
"to replace with name [descriptionBean] and type [java.lang.String].");
}
@@ -140,7 +140,7 @@ class BeanOverrideBeanFactoryPostProcessorTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("Unable to override bean: no bean definitions of type java.lang.Integer " +
.withMessage("Unable to override bean: no beans of type java.lang.Integer " +
"(as required by annotated field 'CaseByType.counter')");
}
@@ -152,7 +152,7 @@ class BeanOverrideBeanFactoryPostProcessorTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("Unable to select a bean definition to override: found 2 bean definitions " +
.withMessage("Unable to select a bean to override: found 2 beans " +
"of type java.lang.Integer (as required by annotated field 'CaseByType.counter'): " +
"[someInteger, anotherInteger]");
}
@@ -388,24 +388,24 @@ class BeanOverrideBeanFactoryPostProcessorTests {
static class CaseByNameWithReplaceOrCreateStrategy {
@DummyBean(beanName = "descriptionBean", strategy = BeanOverrideStrategy.REPLACE_OR_CREATE_DEFINITION)
@DummyBean(beanName = "descriptionBean", strategy = BeanOverrideStrategy.REPLACE_OR_CREATE)
private String description;
}
static class CaseByTypeWithReplaceOrCreateStrategy {
@DummyBean(strategy = BeanOverrideStrategy.REPLACE_OR_CREATE_DEFINITION)
@DummyBean(strategy = BeanOverrideStrategy.REPLACE_OR_CREATE)
private String description;
}
static class CaseByNameAndByTypeWithReplaceOrCreateStrategy {
@DummyBean(beanName = "descriptionBean", strategy = BeanOverrideStrategy.REPLACE_OR_CREATE_DEFINITION)
@DummyBean(beanName = "descriptionBean", strategy = BeanOverrideStrategy.REPLACE_OR_CREATE)
private String description;
@DummyBean(strategy = BeanOverrideStrategy.REPLACE_OR_CREATE_DEFINITION)
@DummyBean(strategy = BeanOverrideStrategy.REPLACE_OR_CREATE)
private Integer counter;
}

View File

@@ -69,7 +69,7 @@ class BeanOverrideContextCustomizerFactoryTests {
private Consumer<OverrideMetadata> dummyMetadata(@Nullable String beanName, Class<?> beanType) {
return dummyMetadata(beanName, beanType, BeanOverrideStrategy.REPLACE_DEFINITION);
return dummyMetadata(beanName, beanType, BeanOverrideStrategy.REPLACE);
}
private Consumer<OverrideMetadata> dummyMetadata(@Nullable String beanName, Class<?> beanType, BeanOverrideStrategy strategy) {

View File

@@ -72,7 +72,7 @@ class BeanOverrideContextCustomizerTests {
public DummyOverrideMetadata(String key) {
super(ReflectionUtils.findField(DummyOverrideMetadata.class, "key"),
ResolvableType.forClass(Object.class), null, BeanOverrideStrategy.REPLACE_DEFINITION);
ResolvableType.forClass(Object.class), null, BeanOverrideStrategy.REPLACE);
this.key = key;
}

View File

@@ -45,7 +45,7 @@ import org.springframework.util.StringUtils;
String beanName() default "";
BeanOverrideStrategy strategy() default BeanOverrideStrategy.REPLACE_DEFINITION;
BeanOverrideStrategy strategy() default BeanOverrideStrategy.REPLACE;
class DummyBeanOverrideProcessor implements BeanOverrideProcessor {

View File

@@ -185,7 +185,7 @@ class OverrideMetadataTests {
}
private static OverrideMetadata createMetadata(Field field, @Nullable String name) {
return new DummyOverrideMetadata(field, field.getType(), name, BeanOverrideStrategy.REPLACE_DEFINITION);
return new DummyOverrideMetadata(field, field.getType(), name, BeanOverrideStrategy.REPLACE);
}
private static Field field(Class<?> target, String fieldName) {
@@ -195,7 +195,7 @@ class OverrideMetadataTests {
}
private static Consumer<OverrideMetadata> hasOverrideMetadata(Field field, Class<?> beanType, @Nullable String beanName) {
return hasOverrideMetadata(field, beanType, BeanOverrideStrategy.REPLACE_DEFINITION, beanName);
return hasOverrideMetadata(field, beanType, BeanOverrideStrategy.REPLACE, beanName);
}
private static Consumer<OverrideMetadata> hasOverrideMetadata(Field field, Class<?> beanType, BeanOverrideStrategy strategy,

View File

@@ -126,7 +126,7 @@ class TestBeanOverrideMetadataTests {
TestBean annotation = field.getAnnotation(TestBean.class);
String beanName = (StringUtils.hasText(annotation.name()) ? annotation.name() : null);
return new TestBeanOverrideMetadata(
field, ResolvableType.forClass(field.getType()), beanName, BeanOverrideStrategy.REPLACE_DEFINITION, overrideMethod);
field, ResolvableType.forClass(field.getType()), beanName, BeanOverrideStrategy.REPLACE, overrideMethod);
}
static class SampleOneOverride {

View File

@@ -40,7 +40,7 @@ public class TestBeanTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
Unable to override bean: there is no bean definition \
Unable to override bean: there is no bean \
to replace with name [beanToOverride] and type [java.lang.String].""");
}
@@ -52,7 +52,7 @@ public class TestBeanTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
Unable to override bean: there is no bean definition \
Unable to override bean: there is no bean \
to replace with name [beanToOverride] and type [java.lang.String].""");
}
@@ -63,7 +63,7 @@ public class TestBeanTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
Unable to override bean: no bean definitions of \
Unable to override bean: no beans of \
type %s (as required by annotated field '%s.example')""".formatted(
String.class.getName(), FailureByTypeLookup.class.getSimpleName()));
}
@@ -77,7 +77,7 @@ public class TestBeanTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
Unable to select a bean definition to override: found 2 bean definitions \
Unable to select a bean to override: found 2 beans \
of type %s (as required by annotated field '%s.example'): %s""".formatted(
String.class.getName(), FailureByTypeLookup.class.getSimpleName(), List.of("bean1", "bean2")));
}

View File

@@ -27,7 +27,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.test.context.bean.override.OverrideMetadata;
import static org.springframework.test.context.bean.override.BeanOverrideStrategy.REPLACE_OR_CREATE_DEFINITION;
import static org.springframework.test.context.bean.override.BeanOverrideStrategy.REPLACE_OR_CREATE;
/**
* {@link OverrideMetadata} that provides support for {@link EasyMockBean @EasyMockBean}.
@@ -43,7 +43,7 @@ class EasyMockBeanOverrideMetadata extends OverrideMetadata {
EasyMockBeanOverrideMetadata(Field field, Class<?> typeToOverride, @Nullable String beanName,
MockType mockType) {
super(field, ResolvableType.forClass(typeToOverride), beanName, REPLACE_OR_CREATE_DEFINITION);
super(field, ResolvableType.forClass(typeToOverride), beanName, REPLACE_OR_CREATE);
this.mockType = mockType;
}

View File

@@ -41,7 +41,7 @@ class MockitoMockBeanTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
Unable to override bean: there is no bean definition \
Unable to override bean: there is no bean \
to replace with name [beanToOverride] and type [java.lang.String].""");
}
@@ -53,7 +53,7 @@ class MockitoMockBeanTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
Unable to override bean: there is no bean definition \
Unable to override bean: there is no bean \
to replace with name [beanToOverride] and type [java.lang.String].""");
}
@@ -64,7 +64,7 @@ class MockitoMockBeanTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
Unable to override bean: no bean definitions of \
Unable to override bean: no beans of \
type %s (as required by annotated field '%s.example')""".formatted(
String.class.getName(), FailureByTypeLookup.class.getSimpleName()));
}
@@ -78,7 +78,7 @@ class MockitoMockBeanTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
Unable to select a bean definition to override: found 2 bean definitions \
Unable to select a bean to override: found 2 beans \
of type %s (as required by annotated field '%s.example'): %s""".formatted(
String.class.getName(), FailureByTypeLookup.class.getSimpleName(), List.of("bean1", "bean2")));
}

View File

@@ -41,7 +41,7 @@ class MockitoSpyBeanTests {
.isThrownBy(context::refresh)
.withMessage("""
Unable to override bean by wrapping: \
there is no existing bean definition with name [beanToSpy] and type [%s].""",
there is no existing bean with name [beanToSpy] and type [%s].""",
String.class.getName());
}