mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Merge branch '6.2.x'
This commit is contained in:
+10
-2
@@ -93,9 +93,17 @@ public class BeanOverrideTestExecutionListener extends AbstractTestExecutionList
|
||||
* a corresponding bean override instance.
|
||||
*/
|
||||
private static void injectFields(TestContext testContext) {
|
||||
List<BeanOverrideHandler> handlers = BeanOverrideHandler.forTestClass(testContext.getTestClass());
|
||||
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
|
||||
// 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
|
||||
// test instance as the "test class".
|
||||
Class<?> testClass = testInstance.getClass();
|
||||
|
||||
List<BeanOverrideHandler> handlers = BeanOverrideHandler.forTestClass(testClass);
|
||||
if (!handlers.isEmpty()) {
|
||||
Object testInstance = testContext.getTestInstance();
|
||||
ApplicationContext applicationContext = testContext.getApplicationContext();
|
||||
|
||||
Assert.state(applicationContext.containsBean(BeanOverrideRegistry.BEAN_NAME), () -> """
|
||||
|
||||
+6
-5
@@ -302,18 +302,19 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
|
||||
Parameter parameter = parameterContext.getParameter();
|
||||
Class<?> parameterType = parameter.getType();
|
||||
Executable executable = parameter.getDeclaringExecutable();
|
||||
PropertyProvider junitPropertyProvider = propertyName ->
|
||||
extensionContext.getConfigurationParameter(propertyName).orElse(null);
|
||||
return (TestConstructorUtils.isAutowirableConstructor(executable, junitPropertyProvider) ||
|
||||
ApplicationContext.class.isAssignableFrom(parameter.getType()) ||
|
||||
supportsApplicationEvents(parameterContext) ||
|
||||
ApplicationContext.class.isAssignableFrom(parameterType) ||
|
||||
supportsApplicationEvents(parameterType, executable) ||
|
||||
ParameterResolutionDelegate.isAutowirable(parameter, parameterContext.getIndex()));
|
||||
}
|
||||
|
||||
private boolean supportsApplicationEvents(ParameterContext parameterContext) {
|
||||
if (ApplicationEvents.class.isAssignableFrom(parameterContext.getParameter().getType())) {
|
||||
Assert.isTrue(parameterContext.getDeclaringExecutable() instanceof Method,
|
||||
private boolean supportsApplicationEvents(Class<?> parameterType, Executable executable) {
|
||||
if (ApplicationEvents.class.isAssignableFrom(parameterType)) {
|
||||
Assert.isTrue(executable instanceof Method,
|
||||
"ApplicationEvents can only be injected into test and lifecycle methods");
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user