From 90c5f226b62503b492167bcd87361842f73d18b1 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 27 Oct 2012 20:42:06 +0200 Subject: [PATCH] Fix package cycles in spring-test Code introduced in conjunction with SPR-5243 introduced package cycles between the ~.test.context.web and ~.test.context.support packages. This was caused by the fact that ServletTestExecutionListener extended AbstractTestExecutionListener. To address this, ServletTestExecutionListener now implements TestExecutionListener directly. Issue: SPR-9924 --- .../web/ServletTestExecutionListener.java | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/web/ServletTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/web/ServletTestExecutionListener.java index 86e9a9f2a0..969234061e 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/ServletTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/ServletTestExecutionListener.java @@ -20,6 +20,7 @@ import javax.servlet.ServletContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; @@ -27,7 +28,7 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockServletContext; import org.springframework.test.context.TestContext; -import org.springframework.test.context.support.AbstractTestExecutionListener; +import org.springframework.test.context.TestExecutionListener; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletWebRequest; @@ -38,17 +39,26 @@ import org.springframework.web.context.request.ServletWebRequest; * @author Sam Brannen * @since 3.2 */ -public class ServletTestExecutionListener extends AbstractTestExecutionListener { +public class ServletTestExecutionListener implements TestExecutionListener { private static final Log logger = LogFactory.getLog(ServletTestExecutionListener.class); + /** + * The default implementation is empty. Can be overridden by + * subclasses as necessary. + * + * @see org.springframework.test.context.TestExecutionListener#beforeTestClass(TestContext) + */ + public void beforeTestClass(TestContext testContext) throws Exception { + /* no-op */ + } + /** * TODO [SPR-9864] Document overridden prepareTestInstance(). * - * @see org.springframework.test.context.support.AbstractTestExecutionListener#prepareTestInstance(org.springframework.test.context.TestContext) + * @see org.springframework.test.context.TestExecutionListener#prepareTestInstance(TestContext) */ - @Override public void prepareTestInstance(TestContext testContext) throws Exception { setUpRequestContextIfNecessary(testContext); } @@ -56,13 +66,34 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener /** * TODO [SPR-9864] Document overridden beforeTestMethod(). * - * @see org.springframework.test.context.support.AbstractTestExecutionListener#beforeTestMethod(org.springframework.test.context.TestContext) + * @see org.springframework.test.context.TestExecutionListener#beforeTestMethod(TestContext) */ - @Override public void beforeTestMethod(TestContext testContext) throws Exception { setUpRequestContextIfNecessary(testContext); } + /** + * TODO [SPR-9864] Document overridden afterTestMethod(). + * + * @see org.springframework.test.context.TestExecutionListener#afterTestMethod(TestContext) + */ + public void afterTestMethod(TestContext testContext) throws Exception { + if (logger.isDebugEnabled()) { + logger.debug(String.format("Resetting RequestContextHolder for test context %s.", testContext)); + } + RequestContextHolder.resetRequestAttributes(); + } + + /** + * The default implementation is empty. Can be overridden by + * subclasses as necessary. + * + * @see org.springframework.test.context.TestExecutionListener#afterTestClass(TestContext) + */ + public void afterTestClass(TestContext testContext) throws Exception { + /* no-op */ + } + /** * TODO [SPR-9864] Document setUpRequestContext(). * @@ -106,17 +137,4 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener } } - /** - * TODO [SPR-9864] Document overridden afterTestMethod(). - * - * @see org.springframework.test.context.support.AbstractTestExecutionListener#afterTestMethod(org.springframework.test.context.TestContext) - */ - @Override - public void afterTestMethod(TestContext testContext) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(String.format("Resetting RequestContextHolder for test context %s.", testContext)); - } - RequestContextHolder.resetRequestAttributes(); - } - }