2424@ SuppressWarnings ("squid:S1118" )
2525public class CreateTestClass {
2626 private static final ServiceLoader <TestClassWatcher > classWatcherLoader ;
27+ private static final ServiceLoader <TestClassWatcher2 > classWatcher2Loader ;
2728 private static final Logger LOGGER = LoggerFactory .getLogger (CreateTestClass .class );
2829 private static final Map <TestClass , Object > TESTCLASS_TO_RUNNER = new ConcurrentHashMap <>();
2930 private static final Map <Object , TestClass > METHOD_TO_TESTCLASS = new ConcurrentHashMap <>();
3031
3132 static {
3233 classWatcherLoader = ServiceLoader .load (TestClassWatcher .class );
34+ classWatcher2Loader = ServiceLoader .load (TestClassWatcher2 .class );
3335 }
3436
3537 /**
@@ -53,6 +55,9 @@ public static TestClass intercept(@This final Object runner, @SuperCall final Ca
5355 for (TestClassWatcher watcher : classWatcherLoader ) {
5456 watcher .testClassCreated (testClass , runner );
5557 }
58+ for (TestClassWatcher2 watcher : classWatcher2Loader ) {
59+ watcher .testClassCreated (testClass , runner );
60+ }
5661
5762 attachRunnerScheduler (testClass , runner );
5863 return testClass ;
@@ -67,7 +72,7 @@ public static TestClass intercept(@This final Object runner, @SuperCall final Ca
6772 private static void attachRunnerScheduler (final TestClass testClass , final Object runner ) {
6873 try {
6974 RunnerScheduler scheduler = getFieldValue (runner , "scheduler" );
70- setFieldValue (runner , "scheduler" , createRunnerScheduler (testClass , scheduler ));
75+ setFieldValue (runner , "scheduler" , createRunnerScheduler (testClass , runner , scheduler ));
7176 } catch (IllegalAccessException | NoSuchFieldException | SecurityException | IllegalArgumentException e ) {
7277 LOGGER .warn ("Unable to attach notifying runner scheduler" , e );
7378 }
@@ -77,10 +82,12 @@ private static void attachRunnerScheduler(final TestClass testClass, final Objec
7782 * Create notifying runner scheduler, which forwards to the previous scheduler if specified.
7883 *
7984 * @param testClass {@link TestClass} object that was just created
85+ * @param runner {@link ParentRunner} for the specified test class
8086 * @param scheduler runner scheduler that's currently attached to the specified runner (may be {@code null})
8187 * @return new notifying runner scheduler
8288 */
83- private static RunnerScheduler createRunnerScheduler (final TestClass testClass , final RunnerScheduler scheduler ) {
89+ private static RunnerScheduler createRunnerScheduler (final TestClass testClass ,
90+ final Object runner , final RunnerScheduler scheduler ) {
8491 return new RunnerScheduler () {
8592 private AtomicBoolean scheduled = new AtomicBoolean (false );
8693
@@ -89,6 +96,9 @@ public void schedule(Runnable childStatement) {
8996 for (TestClassWatcher watcher : classWatcherLoader ) {
9097 watcher .testClassStarted (testClass );
9198 }
99+ for (TestClassWatcher2 watcher : classWatcher2Loader ) {
100+ watcher .testClassStarted (testClass , runner );
101+ }
92102 }
93103
94104 RunReflectiveCall .fireTestStarted (testClass , childStatement );
@@ -106,6 +116,9 @@ public void finished() {
106116 for (TestClassWatcher watcher : classWatcherLoader ) {
107117 watcher .testClassFinished (testClass );
108118 }
119+ for (TestClassWatcher2 watcher : classWatcher2Loader ) {
120+ watcher .testClassFinished (testClass , runner );
121+ }
109122 }
110123 };
111124 }
0 commit comments