@@ -27,6 +27,7 @@ public class CreateTest {
2727
2828 private static final Map <Integer , Object > HASHCODE_TO_TARGET = new ConcurrentHashMap <>();
2929 private static final Map <String , FrameworkMethod > TARGET_TO_METHOD = new ConcurrentHashMap <>();
30+ private static final Map <String , Object > TARGET_TO_RUNNER = new ConcurrentHashMap <>();
3031 private static final ThreadLocal <ConcurrentMap <Integer , DepthGauge >> METHOD_DEPTH ;
3132 private static final Function <Integer , DepthGauge > NEW_INSTANCE ;
3233 private static final Logger LOGGER = LoggerFactory .getLogger (CreateTest .class );
@@ -69,6 +70,7 @@ public static Object intercept(@This final Object runner, @Argument(0) final Fra
6970 METHOD_DEPTH .get ().remove (hashCode );
7071 LOGGER .debug ("testObjectCreated: {}" , target );
7172 TARGET_TO_METHOD .put (toMapKey (target ), method );
73+ TARGET_TO_RUNNER .put (toMapKey (target ), runner );
7274
7375 // apply parameter-based global timeout
7476 TimeoutUtils .applyTestTimeout (runner , method , target );
@@ -110,6 +112,16 @@ static FrameworkMethod getMethodFor(Object target) {
110112 return TARGET_TO_METHOD .get (toMapKey (target ));
111113 }
112114
115+ /**
116+ * Get the runner associated with the specified test class instance.
117+ *
118+ * @param target test class instance
119+ * @return JUnit class runner
120+ */
121+ static Object getRunnerFor (Object target ) {
122+ return TARGET_TO_RUNNER .get (toMapKey (target ));
123+ }
124+
113125 /**
114126 * Release the mappings associated with the specified runner/method/target group.
115127 *
@@ -121,6 +133,7 @@ static void releaseMappingsFor(Object runner, FrameworkMethod method, Object tar
121133 HASHCODE_TO_TARGET .remove (Objects .hash (runner , method ));
122134 if (target != null ) {
123135 TARGET_TO_METHOD .remove (toMapKey (target ));
136+ TARGET_TO_RUNNER .remove (toMapKey (target ));
124137 }
125138 }
126139}
0 commit comments