Do not proxy test instances based on "original instance" convention
Issue: SPR-17137
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,7 +49,7 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
|
||||
* <p>Permissible values include {@link Boolean#TRUE} and {@link Boolean#FALSE}.
|
||||
*/
|
||||
public static final String REINJECT_DEPENDENCIES_ATTRIBUTE = Conventions.getQualifiedAttributeName(
|
||||
DependencyInjectionTestExecutionListener.class, "reinjectDependencies");
|
||||
DependencyInjectionTestExecutionListener.class, "reinjectDependencies");
|
||||
|
||||
private static final Log logger = LogFactory.getLog(DependencyInjectionTestExecutionListener.class);
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
|
||||
* from the test context, regardless of its value.
|
||||
*/
|
||||
@Override
|
||||
public void prepareTestInstance(final TestContext testContext) throws Exception {
|
||||
public void prepareTestInstance(TestContext testContext) throws Exception {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Performing dependency injection for test context [" + testContext + "].");
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
|
||||
* otherwise, this method will have no effect.
|
||||
*/
|
||||
@Override
|
||||
public void beforeTestMethod(final TestContext testContext) throws Exception {
|
||||
public void beforeTestMethod(TestContext testContext) throws Exception {
|
||||
if (Boolean.TRUE.equals(testContext.getAttribute(REINJECT_DEPENDENCIES_ATTRIBUTE))) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Reinjecting dependencies for test context [" + testContext + "].");
|
||||
@@ -112,11 +112,12 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
|
||||
* @see #prepareTestInstance(TestContext)
|
||||
* @see #beforeTestMethod(TestContext)
|
||||
*/
|
||||
protected void injectDependencies(final TestContext testContext) throws Exception {
|
||||
protected void injectDependencies(TestContext testContext) throws Exception {
|
||||
Object bean = testContext.getTestInstance();
|
||||
Class<?> clazz = testContext.getTestClass();
|
||||
AutowireCapableBeanFactory beanFactory = testContext.getApplicationContext().getAutowireCapableBeanFactory();
|
||||
beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
|
||||
beanFactory.initializeBean(bean, testContext.getTestClass().getName());
|
||||
beanFactory.initializeBean(bean, clazz.getName() + AutowireCapableBeanFactory.ORIGINAL_INSTANCE_SUFFIX);
|
||||
testContext.removeAttribute(REINJECT_DEPENDENCIES_ATTRIBUTE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user