Skip to content

Commit 90c5f22

Browse files
committed
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
1 parent acc8364 commit 90c5f22

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

spring-test/src/main/java/org/springframework/test/context/web/ServletTestExecutionListener.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020

2121
import org.apache.commons.logging.Log;
2222
import org.apache.commons.logging.LogFactory;
23+
2324
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2425
import org.springframework.context.ApplicationContext;
2526
import org.springframework.context.ConfigurableApplicationContext;
2627
import org.springframework.mock.web.MockHttpServletRequest;
2728
import org.springframework.mock.web.MockHttpServletResponse;
2829
import org.springframework.mock.web.MockServletContext;
2930
import org.springframework.test.context.TestContext;
30-
import org.springframework.test.context.support.AbstractTestExecutionListener;
31+
import org.springframework.test.context.TestExecutionListener;
3132
import org.springframework.web.context.WebApplicationContext;
3233
import org.springframework.web.context.request.RequestContextHolder;
3334
import org.springframework.web.context.request.ServletWebRequest;
@@ -38,31 +39,61 @@
3839
* @author Sam Brannen
3940
* @since 3.2
4041
*/
41-
public class ServletTestExecutionListener extends AbstractTestExecutionListener {
42+
public class ServletTestExecutionListener implements TestExecutionListener {
4243

4344
private static final Log logger = LogFactory.getLog(ServletTestExecutionListener.class);
4445

4546

47+
/**
48+
* The default implementation is <em>empty</em>. Can be overridden by
49+
* subclasses as necessary.
50+
*
51+
* @see org.springframework.test.context.TestExecutionListener#beforeTestClass(TestContext)
52+
*/
53+
public void beforeTestClass(TestContext testContext) throws Exception {
54+
/* no-op */
55+
}
56+
4657
/**
4758
* TODO [SPR-9864] Document overridden prepareTestInstance().
4859
*
49-
* @see org.springframework.test.context.support.AbstractTestExecutionListener#prepareTestInstance(org.springframework.test.context.TestContext)
60+
* @see org.springframework.test.context.TestExecutionListener#prepareTestInstance(TestContext)
5061
*/
51-
@Override
5262
public void prepareTestInstance(TestContext testContext) throws Exception {
5363
setUpRequestContextIfNecessary(testContext);
5464
}
5565

5666
/**
5767
* TODO [SPR-9864] Document overridden beforeTestMethod().
5868
*
59-
* @see org.springframework.test.context.support.AbstractTestExecutionListener#beforeTestMethod(org.springframework.test.context.TestContext)
69+
* @see org.springframework.test.context.TestExecutionListener#beforeTestMethod(TestContext)
6070
*/
61-
@Override
6271
public void beforeTestMethod(TestContext testContext) throws Exception {
6372
setUpRequestContextIfNecessary(testContext);
6473
}
6574

75+
/**
76+
* TODO [SPR-9864] Document overridden afterTestMethod().
77+
*
78+
* @see org.springframework.test.context.TestExecutionListener#afterTestMethod(TestContext)
79+
*/
80+
public void afterTestMethod(TestContext testContext) throws Exception {
81+
if (logger.isDebugEnabled()) {
82+
logger.debug(String.format("Resetting RequestContextHolder for test context %s.", testContext));
83+
}
84+
RequestContextHolder.resetRequestAttributes();
85+
}
86+
87+
/**
88+
* The default implementation is <em>empty</em>. Can be overridden by
89+
* subclasses as necessary.
90+
*
91+
* @see org.springframework.test.context.TestExecutionListener#afterTestClass(TestContext)
92+
*/
93+
public void afterTestClass(TestContext testContext) throws Exception {
94+
/* no-op */
95+
}
96+
6697
/**
6798
* TODO [SPR-9864] Document setUpRequestContext().
6899
*
@@ -106,17 +137,4 @@ private void setUpRequestContextIfNecessary(TestContext testContext) {
106137
}
107138
}
108139

109-
/**
110-
* TODO [SPR-9864] Document overridden afterTestMethod().
111-
*
112-
* @see org.springframework.test.context.support.AbstractTestExecutionListener#afterTestMethod(org.springframework.test.context.TestContext)
113-
*/
114-
@Override
115-
public void afterTestMethod(TestContext testContext) throws Exception {
116-
if (logger.isDebugEnabled()) {
117-
logger.debug(String.format("Resetting RequestContextHolder for test context %s.", testContext));
118-
}
119-
RequestContextHolder.resetRequestAttributes();
120-
}
121-
122140
}

0 commit comments

Comments
 (0)