Construct consistent error messages in BeanOverrideBeanFactoryPostProcessor
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.test.context.bean.override;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
@@ -84,8 +85,9 @@ class BeanOverrideBeanFactoryPostProcessorTests {
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("Unable to override bean: there is no bean " +
|
||||
"to replace with name [descriptionBean] and type [java.lang.String].");
|
||||
.withMessage("""
|
||||
Unable to replace bean: there is no bean with name 'descriptionBean' \
|
||||
and type java.lang.String (as required by field 'ByNameTestCase.description').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,8 +97,9 @@ class BeanOverrideBeanFactoryPostProcessorTests {
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("Unable to override bean: there is no bean " +
|
||||
"to replace with name [descriptionBean] and type [java.lang.String].");
|
||||
.withMessage("""
|
||||
Unable to replace bean: there is no bean with name 'descriptionBean' \
|
||||
and type java.lang.String (as required by field 'ByNameTestCase.description').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,8 +144,9 @@ class BeanOverrideBeanFactoryPostProcessorTests {
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("Unable to override bean: no beans of type java.lang.Integer " +
|
||||
"(as required by annotated field 'ByTypeTestCase.counter')");
|
||||
.withMessage("""
|
||||
Unable to override bean: there are no beans of type java.lang.Integer \
|
||||
(as required by field 'ByTypeTestCase.counter').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,9 +157,10 @@ class BeanOverrideBeanFactoryPostProcessorTests {
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("Unable to select a bean to override: found 2 beans " +
|
||||
"of type java.lang.Integer (as required by annotated field 'ByTypeTestCase.counter'): " +
|
||||
"[someInteger, anotherInteger]");
|
||||
.withMessage("""
|
||||
Unable to select a bean to override: found 2 beans of type java.lang.Integer \
|
||||
(as required by field 'ByTypeTestCase.counter'): %s""",
|
||||
List.of("someInteger", "anotherInteger"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -40,8 +40,8 @@ public class TestBeanTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean: there is no bean \
|
||||
to replace with name [beanToOverride] and type [java.lang.String].""");
|
||||
Unable to replace bean: there is no bean with name 'beanToOverride' \
|
||||
and type java.lang.String (as required by field 'FailureByNameLookup.example').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,8 +52,8 @@ public class TestBeanTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean: there is no bean \
|
||||
to replace with name [beanToOverride] and type [java.lang.String].""");
|
||||
Unable to replace bean: there is no bean with name 'beanToOverride' \
|
||||
and type java.lang.String (as required by field 'FailureByNameLookup.example').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,8 +63,8 @@ public class TestBeanTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean: no beans of \
|
||||
type %s (as required by annotated field '%s.example')""".formatted(
|
||||
Unable to override bean: there are no beans of \
|
||||
type %s (as required by field '%s.example').""".formatted(
|
||||
String.class.getName(), FailureByTypeLookup.class.getSimpleName()));
|
||||
}
|
||||
|
||||
@@ -77,9 +77,8 @@ public class TestBeanTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
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")));
|
||||
Unable to select a bean to override: found 2 beans of type java.lang.String \
|
||||
(as required by field 'FailureByTypeLookup.example'): %s""", List.of("bean1", "bean2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -41,8 +41,8 @@ class MockitoBeanConfigurationErrorTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean: there is no bean \
|
||||
to replace with name [beanToOverride] and type [java.lang.String].""");
|
||||
Unable to replace bean: there is no bean with name 'beanToOverride' \
|
||||
and type java.lang.String (as required by field 'FailureByNameLookup.example').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,8 +53,8 @@ class MockitoBeanConfigurationErrorTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean: there is no bean \
|
||||
to replace with name [beanToOverride] and type [java.lang.String].""");
|
||||
Unable to replace bean: there is no bean with name 'beanToOverride' \
|
||||
and type java.lang.String (as required by field 'FailureByNameLookup.example').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,9 +64,8 @@ class MockitoBeanConfigurationErrorTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean: no beans of \
|
||||
type %s (as required by annotated field '%s.example')""".formatted(
|
||||
String.class.getName(), FailureByTypeLookup.class.getSimpleName()));
|
||||
Unable to override bean: there are no beans of \
|
||||
type java.lang.String (as required by field 'FailureByTypeLookup.example').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,9 +77,9 @@ class MockitoBeanConfigurationErrorTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
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")));
|
||||
Unable to select a bean to override: found 2 beans of type java.lang.String \
|
||||
(as required by field 'FailureByTypeLookup.example'): %s""",
|
||||
List.of("bean1", "bean2"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,10 +40,9 @@ class MockitoSpyBeanConfigurationErrorTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean by wrapping: \
|
||||
there is no existing bean with name [beanToSpy] and type [%s].""",
|
||||
String.class.getName());
|
||||
}
|
||||
Unable to wrap bean: there is no bean with name 'beanToSpy' and \
|
||||
type java.lang.String (as required by field 'ByNameSingleLookup.example').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
void contextCustomizerCannotBeCreatedWithNoSuchBeanType() {
|
||||
@@ -52,9 +51,8 @@ class MockitoSpyBeanConfigurationErrorTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to select a bean to override by wrapping: found 0 bean instances of \
|
||||
type %s (as required by annotated field '%s.example')""",
|
||||
String.class.getName(), ByTypeSingleLookup.class.getSimpleName());
|
||||
Unable to select a bean to wrap: there are no beans of type java.lang.String \
|
||||
(as required by field 'ByTypeSingleLookup.example').""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,9 +64,9 @@ class MockitoSpyBeanConfigurationErrorTests {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to select a bean to override by wrapping: found 2 bean instances \
|
||||
of type %s (as required by annotated field '%s.example'): %s""",
|
||||
String.class.getName(), ByTypeSingleLookup.class.getSimpleName(), List.of("bean1", "bean2"));
|
||||
Unable to select a bean to wrap: found 2 beans of type java.lang.String \
|
||||
(as required by field 'ByTypeSingleLookup.example'): %s""",
|
||||
List.of("bean1", "bean2"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user