@@ -151,6 +151,32 @@ public void postProcessTestInstance(Object testInstance, ExtensionContext contex
151
151
getTestContextManager (context ).prepareTestInstance (testInstance );
152
152
}
153
153
154
+ /**
155
+ * Validate that test methods and test lifecycle methods in the supplied
156
+ * test class are not annotated with {@link Autowired @Autowired}.
157
+ * @since 5.3.2
158
+ */
159
+ private void validateAutowiredConfig (ExtensionContext context ) {
160
+ // We save the result in the ExtensionContext.Store so that we don't
161
+ // re-validate all methods for the same test class multiple times.
162
+ Store store = context .getStore (AUTOWIRED_VALIDATION_NAMESPACE );
163
+
164
+ String errorMessage = store .getOrComputeIfAbsent (context .getRequiredTestClass (), testClass -> {
165
+ Method [] methodsWithErrors =
166
+ ReflectionUtils .getUniqueDeclaredMethods (testClass , autowiredTestOrLifecycleMethodFilter );
167
+ return (methodsWithErrors .length == 0 ? NO_VIOLATIONS_DETECTED :
168
+ String .format (
169
+ "Test methods and test lifecycle methods must not be annotated with @Autowired. " +
170
+ "You should instead annotate individual method parameters with @Autowired, " +
171
+ "@Qualifier, or @Value. Offending methods in test class %s: %s" ,
172
+ testClass .getName (), Arrays .toString (methodsWithErrors )));
173
+ }, String .class );
174
+
175
+ if (errorMessage != NO_VIOLATIONS_DETECTED ) {
176
+ throw new IllegalStateException (errorMessage );
177
+ }
178
+ }
179
+
154
180
/**
155
181
* Validate that the test class or its enclosing class doesn't attempt to record
156
182
* application events in a parallel mode that makes it non-deterministic
@@ -160,7 +186,7 @@ public void postProcessTestInstance(Object testInstance, ExtensionContext contex
160
186
*/
161
187
private void validateRecordApplicationEventsConfig (ExtensionContext context ) {
162
188
// We save the result in the ExtensionContext.Store so that we don't
163
- // re-validate all methods for the same test class multiple times.
189
+ // re-validate the configuration for the same test class multiple times.
164
190
Store store = context .getStore (RECORD_APPLICATION_EVENTS_VALIDATION_NAMESPACE );
165
191
166
192
String errorMessage = store .getOrComputeIfAbsent (context .getRequiredTestClass (), testClass -> {
@@ -190,32 +216,6 @@ private void validateRecordApplicationEventsConfig(ExtensionContext context) {
190
216
}
191
217
}
192
218
193
- /**
194
- * Validate that test methods and test lifecycle methods in the supplied
195
- * test class are not annotated with {@link Autowired @Autowired}.
196
- * @since 5.3.2
197
- */
198
- private void validateAutowiredConfig (ExtensionContext context ) {
199
- // We save the result in the ExtensionContext.Store so that we don't
200
- // re-validate all methods for the same test class multiple times.
201
- Store store = context .getStore (AUTOWIRED_VALIDATION_NAMESPACE );
202
-
203
- String errorMessage = store .getOrComputeIfAbsent (context .getRequiredTestClass (), testClass -> {
204
- Method [] methodsWithErrors =
205
- ReflectionUtils .getUniqueDeclaredMethods (testClass , autowiredTestOrLifecycleMethodFilter );
206
- return (methodsWithErrors .length == 0 ? NO_VIOLATIONS_DETECTED :
207
- String .format (
208
- "Test methods and test lifecycle methods must not be annotated with @Autowired. " +
209
- "You should instead annotate individual method parameters with @Autowired, " +
210
- "@Qualifier, or @Value. Offending methods in test class %s: %s" ,
211
- testClass .getName (), Arrays .toString (methodsWithErrors )));
212
- }, String .class );
213
-
214
- if (errorMessage != NO_VIOLATIONS_DETECTED ) {
215
- throw new IllegalStateException (errorMessage );
216
- }
217
- }
218
-
219
219
/**
220
220
* Delegates to {@link TestContextManager#beforeTestMethod}.
221
221
*/
0 commit comments