Skip to content

Commit 9797bc0

Browse files
committed
Expose order values of TestExecutionListener implementations as constants
Prior to this commit, the order values of TestExecutionListener implementations were hard-coded in their getOrder() methods. To benefit users and integrators, this commit exposes those order values as an ORDER constant in each TestExecutionListener. See gh-34225 Closes gh-34404
1 parent 9d3374b commit 9797bc0

12 files changed

+99
-25
lines changed

Diff for: spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideTestExecutionListener.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,21 @@
3737
public class BeanOverrideTestExecutionListener extends AbstractTestExecutionListener {
3838

3939
/**
40-
* Returns {@code 1950}, which ensures that the {@code BeanOverrideTestExecutionListener}
40+
* The {@link #getOrder() order} value for this listener: {@value}.
41+
* @since 6.2.3
42+
*/
43+
public static final int ORDER = 1950;
44+
45+
/**
46+
* Returns {@value #ORDER}, which ensures that the {@code BeanOverrideTestExecutionListener}
4147
* is ordered after the
4248
* {@link org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener
4349
* DirtiesContextBeforeModesTestExecutionListener} and before the
4450
* {@link DependencyInjectionTestExecutionListener}.
4551
*/
4652
@Override
4753
public int getOrder() {
48-
return 1950;
54+
return ORDER;
4955
}
5056

5157
/**

Diff for: spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoResetTestExecutionListener.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
*/
5050
public class MockitoResetTestExecutionListener extends AbstractTestExecutionListener {
5151

52+
/**
53+
* The {@link #getOrder() order} value for this listener
54+
* ({@code Ordered.LOWEST_PRECEDENCE - 100}): {@value}.
55+
* @since 6.2.3
56+
*/
57+
public static final int ORDER = Ordered.LOWEST_PRECEDENCE - 100;
58+
5259
private static final Log logger = LogFactory.getLog(MockitoResetTestExecutionListener.class);
5360

5461
/**
@@ -74,9 +81,10 @@ public class MockitoResetTestExecutionListener extends AbstractTestExecutionList
7481

7582

7683
/**
77-
* Returns {@code Ordered.LOWEST_PRECEDENCE - 100}, which ensures that the
84+
* Returns {@value #ORDER}, which ensures that the
7885
* {@code MockitoResetTestExecutionListener} is ordered after all standard
7986
* {@code TestExecutionListener} implementations.
87+
* @see #ORDER
8088
*/
8189
@Override
8290
public int getOrder() {

Diff for: spring-test/src/main/java/org/springframework/test/context/event/ApplicationEventsTestExecutionListener.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
*/
4949
public class ApplicationEventsTestExecutionListener extends AbstractTestExecutionListener {
5050

51+
/**
52+
* The {@link #getOrder() order} value for this listener: {@value}.
53+
* @since 6.2.3
54+
*/
55+
public static final int ORDER = 1800;
56+
5157
/**
5258
* Attribute name for a {@link TestContext} attribute which indicates
5359
* whether the test class for the given test context is annotated with
@@ -61,7 +67,7 @@ public class ApplicationEventsTestExecutionListener extends AbstractTestExecutio
6167

6268

6369
/**
64-
* Returns {@code 1800}, which ensures that the {@code ApplicationEventsTestExecutionListener}
70+
* Returns {@value #ORDER}, which ensures that the {@code ApplicationEventsTestExecutionListener}
6571
* is ordered after the
6672
* {@link org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener
6773
* DirtiesContextBeforeModesTestExecutionListener} and before the
@@ -72,7 +78,7 @@ public class ApplicationEventsTestExecutionListener extends AbstractTestExecutio
7278
*/
7379
@Override
7480
public final int getOrder() {
75-
return 1800;
81+
return ORDER;
7682
}
7783

7884
@Override

Diff for: spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@
9898
public class EventPublishingTestExecutionListener extends AbstractTestExecutionListener {
9999

100100
/**
101-
* Returns {@code 10000}, which ensures that the {@code EventPublishingTestExecutionListener}
101+
* The {@link #getOrder() order} value for this listener: {@value}.
102+
* @since 6.2.3
103+
*/
104+
public static final int ORDER = 10_000;
105+
106+
/**
107+
* Returns {@value #ORDER}, which ensures that the {@code EventPublishingTestExecutionListener}
102108
* is ordered after the
103109
* {@link org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener
104110
* SqlScriptsTestExecutionListener} and before the
@@ -107,7 +113,7 @@ public class EventPublishingTestExecutionListener extends AbstractTestExecutionL
107113
*/
108114
@Override
109115
public final int getOrder() {
110-
return 10_000;
116+
return ORDER;
111117
}
112118

113119
/**

Diff for: spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
*/
118118
public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListener implements AotTestExecutionListener {
119119

120+
/**
121+
* The {@link #getOrder() order} value for this listener: {@value}.
122+
* @since 6.2.3
123+
*/
124+
public static final int ORDER = 5000;
125+
120126
private static final String SLASH = "/";
121127

122128
private static final Log logger = LogFactory.getLog(SqlScriptsTestExecutionListener.class);
@@ -126,7 +132,7 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
126132

127133

128134
/**
129-
* Returns {@code 5000}, which ensures that the {@code SqlScriptsTestExecutionListener}
135+
* Returns {@value #ORDER}, which ensures that the {@code SqlScriptsTestExecutionListener}
130136
* is ordered after the
131137
* {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener
132138
* TransactionalTestExecutionListener} and before the
@@ -135,7 +141,7 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
135141
*/
136142
@Override
137143
public final int getOrder() {
138-
return 5000;
144+
return ORDER;
139145
}
140146

141147
/**

Diff for: spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
*/
4545
class MicrometerObservationRegistryTestExecutionListener extends AbstractTestExecutionListener {
4646

47+
/**
48+
* The {@link #getOrder() order} value for this listener: {@value}.
49+
* @since 6.2.3
50+
*/
51+
public static final int ORDER = 2500;
52+
4753
private static final Log logger = LogFactory.getLog(MicrometerObservationRegistryTestExecutionListener.class);
4854

4955
/**
@@ -107,7 +113,7 @@ public MicrometerObservationRegistryTestExecutionListener() {
107113

108114

109115
/**
110-
* Returns {@code 2500}, which ensures that the
116+
* Returns {@value #ORDER}, which ensures that the
111117
* {@code MicrometerObservationRegistryTestExecutionListener} is ordered after the
112118
* {@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener
113119
* DependencyInjectionTestExecutionListener} and before the
@@ -116,7 +122,7 @@ public MicrometerObservationRegistryTestExecutionListener() {
116122
*/
117123
@Override
118124
public final int getOrder() {
119-
return 2500;
125+
return ORDER;
120126
}
121127

122128
/**

Diff for: spring-test/src/main/java/org/springframework/test/context/support/CommonCachesTestExecutionListener.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,24 @@
3636
public class CommonCachesTestExecutionListener extends AbstractTestExecutionListener {
3737

3838
/**
39-
* Returns {@code 3005}, which ensures that the {@code CommonCachesTestExecutionListener}
39+
* The {@link #getOrder() order} value for this listener: {@value}.
40+
* @since 6.2.3
41+
*/
42+
public static final int ORDER = 3005;
43+
44+
45+
/**
46+
* Returns {@value #ORDER}, which ensures that the {@code CommonCachesTestExecutionListener}
4047
* is ordered after the
4148
* {@link DirtiesContextTestExecutionListener DirtiesContextTestExecutionListener} and before the
4249
* {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener
4350
* TransactionalTestExecutionListener}.
4451
*/
4552
@Override
4653
public final int getOrder() {
47-
return 3005;
54+
return ORDER;
4855
}
4956

50-
5157
@Override
5258
public void afterTestClass(TestContext testContext) throws Exception {
5359
if (testContext.hasApplicationContext()) {

Diff for: spring-test/src/main/java/org/springframework/test/context/support/DependencyInjectionTestExecutionListener.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
*/
4040
public class DependencyInjectionTestExecutionListener extends AbstractTestExecutionListener {
4141

42+
/**
43+
* The {@link #getOrder() order} value for this listener: {@value}.
44+
* @since 6.2.3
45+
*/
46+
public static final int ORDER = 2000;
47+
4248
/**
4349
* Attribute name for a {@link TestContext} attribute which indicates
4450
* whether the dependencies of a test instance should be
@@ -63,7 +69,7 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
6369

6470

6571
/**
66-
* Returns {@code 2000}, which ensures that the {@code DependencyInjectionTestExecutionListener}
72+
* Returns {@value #ORDER}, which ensures that the {@code DependencyInjectionTestExecutionListener}
6773
* is ordered after the
6874
* {@link DirtiesContextBeforeModesTestExecutionListener DirtiesContextBeforeModesTestExecutionListener}
6975
* and the {@link org.springframework.test.context.bean.override.BeanOverrideTestExecutionListener
@@ -74,7 +80,7 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
7480
*/
7581
@Override
7682
public final int getOrder() {
77-
return 2000;
83+
return ORDER;
7884
}
7985

8086
/**

Diff for: spring-test/src/main/java/org/springframework/test/context/support/DirtiesContextBeforeModesTestExecutionListener.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@
5555
public class DirtiesContextBeforeModesTestExecutionListener extends AbstractDirtiesContextTestExecutionListener {
5656

5757
/**
58-
* Returns {@code 1500}, which ensures that the {@code DirtiesContextBeforeModesTestExecutionListener}
59-
* is ordered after the
58+
* The {@link #getOrder() order} value for this listener: {@value}.
59+
* @since 6.2.3
60+
*/
61+
public static final int ORDER = 1500;
62+
63+
/**
64+
* Returns {@value #ORDER}, which ensures that the
65+
* {@code DirtiesContextBeforeModesTestExecutionListener} is ordered after the
6066
* {@link org.springframework.test.context.web.ServletTestExecutionListener
6167
* ServletTestExecutionListener} and before the
6268
* {@link org.springframework.test.context.event.ApplicationEventsTestExecutionListener
@@ -66,7 +72,7 @@ public class DirtiesContextBeforeModesTestExecutionListener extends AbstractDirt
6672
*/
6773
@Override
6874
public final int getOrder() {
69-
return 1500;
75+
return ORDER;
7076
}
7177

7278
/**

Diff for: spring-test/src/main/java/org/springframework/test/context/support/DirtiesContextTestExecutionListener.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,20 @@
5555
public class DirtiesContextTestExecutionListener extends AbstractDirtiesContextTestExecutionListener {
5656

5757
/**
58-
* Returns {@code 3000}, which ensures that the {@code DirtiesContextTestExecutionListener}
58+
* The {@link #getOrder() order} value for this listener: {@value}.
59+
* @since 6.2.3
60+
*/
61+
public static final int ORDER = 3000;
62+
63+
/**
64+
* Returns {@value #ORDER}, which ensures that the {@code DirtiesContextTestExecutionListener}
5965
* is ordered after the
6066
* {@link DependencyInjectionTestExecutionListener DependencyInjectionTestExecutionListener}
6167
* and before the {@link CommonCachesTestExecutionListener CommonCachesTestExecutionListener}.
6268
*/
6369
@Override
6470
public final int getOrder() {
65-
return 3000;
71+
return ORDER;
6672
}
6773

6874
/**

Diff for: spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@
148148
*/
149149
public class TransactionalTestExecutionListener extends AbstractTestExecutionListener {
150150

151+
/**
152+
* The {@link #getOrder() order} value for this listener: {@value}.
153+
* @since 6.2.3
154+
*/
155+
public static final int ORDER = 4000;
156+
151157
private static final Log logger = LogFactory.getLog(TransactionalTestExecutionListener.class);
152158

153159
// Do not require @Transactional test methods to be public.
@@ -177,7 +183,7 @@ private TransactionAttribute findTransactionAttributeInEnclosingClassHierarchy(C
177183

178184

179185
/**
180-
* Returns {@code 4000}, which ensures that the {@code TransactionalTestExecutionListener}
186+
* Returns {@value #ORDER}, which ensures that the {@code TransactionalTestExecutionListener}
181187
* is ordered after the
182188
* {@link org.springframework.test.context.support.CommonCachesTestExecutionListener
183189
* CommonCachesTestExecutionListener} and before the
@@ -186,7 +192,7 @@ private TransactionAttribute findTransactionAttributeInEnclosingClassHierarchy(C
186192
*/
187193
@Override
188194
public final int getOrder() {
189-
return 4000;
195+
return ORDER;
190196
}
191197

192198
/**

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
*/
6565
public class ServletTestExecutionListener extends AbstractTestExecutionListener {
6666

67+
/**
68+
* The {@link #getOrder() order} value for this listener: {@value}.
69+
* @since 6.2.3
70+
*/
71+
public static final int ORDER = 1000;
72+
6773
/**
6874
* Attribute name for a {@link TestContext} attribute which indicates
6975
* whether the {@code ServletTestExecutionListener} should {@linkplain
@@ -110,14 +116,14 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
110116

111117

112118
/**
113-
* Returns {@code 1000}, which ensures that the {@code ServletTestExecutionListener}
119+
* Returns {@value #ORDER}, which ensures that the {@code ServletTestExecutionListener}
114120
* is ordered before the
115121
* {@link org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener
116122
* DirtiesContextBeforeModesTestExecutionListener}.
117123
*/
118124
@Override
119125
public final int getOrder() {
120-
return 1000;
126+
return ORDER;
121127
}
122128

123129
/**

0 commit comments

Comments
 (0)