Improve diagnostics when a Bean Override cannot be selected by type

See gh-34004
Closes gh-34006

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
This commit is contained in:
Yanming Zhou
2024-11-26 15:04:37 +08:00
committed by Sam Brannen
parent 2b4c7d09b0
commit cf46f391d7
5 changed files with 21 additions and 13 deletions

View File

@@ -85,7 +85,7 @@ class BeanOverrideBeanFactoryPostProcessorTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to replace bean: there is no bean with name 'descriptionBean' \
and type java.lang.String (as required by field 'ByNameTestCase.description').""");
}
@@ -97,7 +97,7 @@ class BeanOverrideBeanFactoryPostProcessorTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to replace bean: there is no bean with name 'descriptionBean' \
and type java.lang.String (as required by field 'ByNameTestCase.description').""");
}
@@ -144,7 +144,7 @@ class BeanOverrideBeanFactoryPostProcessorTests {
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to override bean: there are no beans of type java.lang.Integer \
(as required by field 'ByTypeTestCase.counter').""");
}

View File

@@ -40,7 +40,7 @@ public class TestBeanTests {
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context);
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to replace bean: there is no bean with name 'beanToOverride' \
and type java.lang.String (as required by field 'FailureByNameLookup.example').""");
}
@@ -52,7 +52,7 @@ public class TestBeanTests {
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context);
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to replace bean: there is no bean with name 'beanToOverride' \
and type java.lang.String (as required by field 'FailureByNameLookup.example').""");
}
@@ -63,7 +63,7 @@ public class TestBeanTests {
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByTypeLookup.class, context);
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to override bean: there are no beans of \
type %s (as required by field '%s.example').""",
String.class.getName(), FailureByTypeLookup.class.getSimpleName());

View File

@@ -40,7 +40,7 @@ class MockitoBeanConfigurationErrorTests {
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context);
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to replace bean: there is no bean with name 'beanToOverride' \
and type java.lang.String (as required by field 'FailureByNameLookup.example').""");
}
@@ -52,7 +52,7 @@ class MockitoBeanConfigurationErrorTests {
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context);
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to replace bean: there is no bean with name 'beanToOverride' \
and type java.lang.String (as required by field 'FailureByNameLookup.example').""");
}
@@ -63,7 +63,7 @@ class MockitoBeanConfigurationErrorTests {
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByTypeLookup.class, context);
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to override bean: there are no beans of \
type java.lang.String (as required by field 'FailureByTypeLookup.example').""");
}

View File

@@ -50,7 +50,7 @@ class MockitoSpyBeanConfigurationErrorTests {
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context);
assertThatIllegalStateException()
.isThrownBy(context::refresh)
.withMessage("""
.withMessageStartingWith("""
Unable to select a bean to wrap: there are no beans of type java.lang.String \
(as required by field 'ByTypeSingleLookup.example').""");
}