Update exception message to use correct test class

See gh-35680
This commit is contained in:
Sam Brannen
2025-10-22 18:04:13 +02:00
parent ba70c1384a
commit 0f2fc79fb7
@@ -95,7 +95,7 @@ public class BeanOverrideTestExecutionListener extends AbstractTestExecutionList
private static void injectFields(TestContext testContext) {
Object testInstance = testContext.getTestInstance();
// Since JUnit Jupiter 5.12, if the SpringExtension is used with Jupiter's
// ExtensionContextScope.TEST_METHOD mode, the value returned from
// TEST_METHOD ExtensionContextScope, the value returned from
// testContext.getTestClass() may refer to the declaring class of the test
// method which is about to be invoked (which may be in a @Nested class
// within the class for the test instance). Thus, we use the class for the
@@ -109,7 +109,7 @@ public class BeanOverrideTestExecutionListener extends AbstractTestExecutionList
Assert.state(applicationContext.containsBean(BeanOverrideRegistry.BEAN_NAME), () -> """
Test class %s declares @BeanOverride fields %s, but no BeanOverrideHandler has been registered. \
If you are using @ContextHierarchy, ensure that context names for bean overrides match \
configured @ContextConfiguration names.""".formatted(testContext.getTestClass().getSimpleName(),
configured @ContextConfiguration names.""".formatted(testClass.getSimpleName(),
handlers.stream().map(BeanOverrideHandler::getField).filter(Objects::nonNull)
.map(Field::getName).toList()));
BeanOverrideRegistry beanOverrideRegistry = applicationContext.getBean(BeanOverrideRegistry.BEAN_NAME,