@@ -86,7 +86,7 @@ public static ClassFileTransformer installTransformer(Instrumentation instrument
8686 builder .method (named ("createTestClass" )).intercept (MethodDelegation .to (CreateTestClass .class ))
8787 .method (named ("run" )).intercept (MethodDelegation .to (Run .class ))
8888 .implement (Hooked .class ))
89- .type (is (blockJUnit4ClassRunner ))
89+ .type (isSubTypeOf (blockJUnit4ClassRunner ))
9090 .transform ((builder , type , classLoader , module ) ->
9191 builder .method (named ("createTest" )).intercept (MethodDelegation .to (CreateTest .class ))
9292 .method (named ("runChild" )).intercept (MethodDelegation .to (RunChild .class ))
@@ -196,7 +196,7 @@ static Object getParentOf(Object child) {
196196 public static class CreateTest {
197197
198198 private static final ServiceLoader <TestObjectWatcher > objectWatcherLoader ;
199- private static final Map <Object , TestClass > TARGET_TO_TESTCLASS = new ConcurrentHashMap <>();
199+ private static final Map <Object , Object > TARGET_TO_RUNNER = new ConcurrentHashMap <>();
200200
201201 static {
202202 objectWatcherLoader = ServiceLoader .load (TestObjectWatcher .class );
@@ -214,41 +214,37 @@ public static class CreateTest {
214214 public static Object intercept (@ This final Object runner ,
215215 @ SuperCall final Callable <?> proxy ) throws Exception {
216216 Object testObj = callProxy (proxy );
217- TARGET_TO_TESTCLASS .put (testObj , getTestClassOf ( runner ) );
217+ TARGET_TO_RUNNER .put (testObj , runner );
218218 applyTimeout (testObj );
219219
220220 synchronized (objectWatcherLoader ) {
221221 for (TestObjectWatcher watcher : objectWatcherLoader ) {
222- watcher .testObjectCreated (testObj , TARGET_TO_TESTCLASS . get ( testObj ) );
222+ watcher .testObjectCreated (testObj , runner );
223223 }
224224 }
225225
226226 return testObj ;
227227 }
228228
229229 /**
230- * Get the test class object that wraps the specified instance.
230+ * Get the class runner associated with the specified instance.
231231 *
232232 * @param target instance of JUnit test class
233- * @return {@link TestClass} associated with specified instance
233+ * @return {@link org.junit.runners.BlockJUnit4ClassRunner BlockJUnit4ClassRunner} for specified instance
234234 */
235- static TestClass getTestClassFor (Object target ) {
236- TestClass testClass = TARGET_TO_TESTCLASS .get (target );
237- if (testClass != null ) {
238- return testClass ;
239- }
240- throw new IllegalArgumentException ("No associated test class was found for specified instance" );
235+ static Object getRunnerFor (Object target ) {
236+ return TARGET_TO_RUNNER .get (target );
241237 }
242238 }
243239
244240 /**
245- * Get the test class object that wraps the specified instance.
241+ * Get the class runner associated with the specified instance.
246242 *
247243 * @param target instance of JUnit test class
248- * @return {@link TestClass} associated with specified instance object
244+ * @return {@link org.junit.runners.BlockJUnit4ClassRunner BlockJUnit4ClassRunner} for specified instance
249245 */
250- public static TestClass getTestClassFor (Object target ) {
251- return CreateTest .getTestClassFor (target );
246+ public static Object getRunnerFor (Object target ) {
247+ return CreateTest .getRunnerFor (target );
252248 }
253249
254250 /**
@@ -310,8 +306,7 @@ public static boolean hasConfiguration(TestClass testClass) {
310306 * @return {@link Description} object for the indicated child
311307 */
312308 public static Description describeChild (Object target , Object child ) {
313- TestClass testClass = getTestClassFor (target );
314- Object runner = getRunnerFor (testClass );
309+ Object runner = getRunnerFor (target );
315310 return invoke (runner , "describeChild" , child );
316311 }
317312
0 commit comments