88import org .junit .runner .Description ;
99import org .junit .runner .notification .Failure ;
1010import org .junit .runner .notification .RunListener ;
11- import org .junit .runners .model .FrameworkMethod ;
1211import org .slf4j .Logger ;
1312import org .slf4j .LoggerFactory ;
1413
1514import com .google .common .base .Optional ;
1615
17- public class RunAnnouncer extends RunListener {
16+ public class RunAnnouncer < T > extends RunListener {
1817
18+ @ SuppressWarnings ("rawtypes" )
1919 private static final ServiceLoader <RunWatcher > runWatcherLoader ;
20- private static final Map <Object , AtomicTest > RUNNER_TO_ATOMICTEST = new ConcurrentHashMap <>();
20+ private static final Map <Object , AtomicTest <?> > RUNNER_TO_ATOMICTEST = new ConcurrentHashMap <>();
2121 private static final Logger LOGGER = LoggerFactory .getLogger (RunAnnouncer .class );
2222
2323 static {
@@ -28,11 +28,12 @@ public class RunAnnouncer extends RunListener {
2828 * {@inheritDoc}
2929 */
3030 @ Override
31+ @ SuppressWarnings ("unchecked" )
3132 public void testStarted (Description description ) throws Exception {
3233 LOGGER .debug ("testStarted: {}" , description );
33- AtomicTest atomicTest = getAtomicTestOf (description );
34+ AtomicTest < T > atomicTest = getAtomicTestOf (description );
3435 synchronized (runWatcherLoader ) {
35- for (RunWatcher watcher : runWatcherLoader ) {
36+ for (RunWatcher < T > watcher : runWatcherLoader ) {
3637 watcher .testStarted (atomicTest );
3738 }
3839 }
@@ -42,11 +43,12 @@ public void testStarted(Description description) throws Exception {
4243 * {@inheritDoc}
4344 */
4445 @ Override
46+ @ SuppressWarnings ("unchecked" )
4547 public void testFinished (Description description ) throws Exception {
4648 LOGGER .debug ("testFinished: {}" , description );
47- AtomicTest atomicTest = getAtomicTestOf (description );
49+ AtomicTest < T > atomicTest = getAtomicTestOf (description );
4850 synchronized (runWatcherLoader ) {
49- for (RunWatcher watcher : runWatcherLoader ) {
51+ for (RunWatcher < T > watcher : runWatcherLoader ) {
5052 watcher .testFinished (atomicTest );
5153 }
5254 }
@@ -56,11 +58,12 @@ public void testFinished(Description description) throws Exception {
5658 * {@inheritDoc}
5759 */
5860 @ Override
61+ @ SuppressWarnings ("unchecked" )
5962 public void testFailure (Failure failure ) throws Exception {
6063 LOGGER .debug ("testFailure: {}" , failure );
61- AtomicTest atomicTest = setTestFailure (failure );
64+ AtomicTest < T > atomicTest = setTestFailure (failure );
6265 synchronized (runWatcherLoader ) {
63- for (RunWatcher watcher : runWatcherLoader ) {
66+ for (RunWatcher < T > watcher : runWatcherLoader ) {
6467 watcher .testFailure (atomicTest , failure .getException ());
6568 }
6669 }
@@ -70,11 +73,12 @@ public void testFailure(Failure failure) throws Exception {
7073 * {@inheritDoc}
7174 */
7275 @ Override
76+ @ SuppressWarnings ("unchecked" )
7377 public void testAssumptionFailure (Failure failure ) {
7478 LOGGER .debug ("testAssumptionFailure: {}" , failure );
75- AtomicTest atomicTest = setTestFailure (failure );
79+ AtomicTest < T > atomicTest = setTestFailure (failure );
7680 synchronized (runWatcherLoader ) {
77- for (RunWatcher watcher : runWatcherLoader ) {
81+ for (RunWatcher < T > watcher : runWatcherLoader ) {
7882 watcher .testAssumptionFailure (atomicTest , (AssumptionViolatedException ) failure .getException ());
7983 }
8084 }
@@ -84,24 +88,27 @@ public void testAssumptionFailure(Failure failure) {
8488 * {@inheritDoc}
8589 */
8690 @ Override
91+ @ SuppressWarnings ("unchecked" )
8792 public void testIgnored (Description description ) throws Exception {
8893 LOGGER .debug ("testIgnored: {}" , description );
89- AtomicTest atomicTest = getAtomicTestOf (description );
94+ AtomicTest < T > atomicTest = getAtomicTestOf (description );
9095 synchronized (runWatcherLoader ) {
91- for (RunWatcher watcher : runWatcherLoader ) {
96+ for (RunWatcher < T > watcher : runWatcherLoader ) {
9297 watcher .testIgnored (atomicTest );
9398 }
9499 }
95100 }
96101
97102 /**
98- * Create new atomic test object for the specified description .
103+ * Create new atomic test object for the specified runner/child pair .
99104 *
100- * @param description {@link Description} object
105+ * @param <T> type of children associated with the specified runner
106+ * @param runner parent runner
107+ * @param identity identity for this atomic test
101108 * @return {@link AtomicTest} object
102109 */
103- static AtomicTest newAtomicTest (Object runner , FrameworkMethod method ) {
104- AtomicTest atomicTest = new AtomicTest (runner , method );
110+ static < T > AtomicTest < T > newAtomicTest (Object runner , T identity ) {
111+ AtomicTest < T > atomicTest = new AtomicTest <> (runner , identity );
105112 RUNNER_TO_ATOMICTEST .put (runner , atomicTest );
106113 RUNNER_TO_ATOMICTEST .put (atomicTest .getDescription (), atomicTest );
107114 return atomicTest ;
@@ -113,8 +120,9 @@ static AtomicTest newAtomicTest(Object runner, FrameworkMethod method) {
113120 * @param testKey JUnit class runner or method description
114121 * @return {@link AtomicTest} object (may be {@code null})
115122 */
116- static AtomicTest getAtomicTestOf (Object testKey ) {
117- return RUNNER_TO_ATOMICTEST .get (testKey );
123+ @ SuppressWarnings ("unchecked" )
124+ static <T > AtomicTest <T > getAtomicTestOf (Object testKey ) {
125+ return (AtomicTest <T >) RUNNER_TO_ATOMICTEST .get (testKey );
118126 }
119127
120128 /**
@@ -123,26 +131,26 @@ static AtomicTest getAtomicTestOf(Object testKey) {
123131 * @param failure {@link Failure} object
124132 * @return {@link AtomicTest} object
125133 */
126- private static AtomicTest setTestFailure (Failure failure ) {
127- AtomicTest atomicTest = getAtomicTestOf (Run .getThreadRunner ());
134+ private static < T > AtomicTest < T > setTestFailure (Failure failure ) {
135+ AtomicTest < T > atomicTest = getAtomicTestOf (Run .getThreadRunner ());
128136 atomicTest .setThrowable (failure .getException ());
129137 return atomicTest ;
130138 }
131139
132140 /**
133141 * Get reference to an instance of the specified watcher type.
134142 *
135- * @param <T > watcher type
143+ * @param <W > watcher type
136144 * @param watcherType watcher type
137145 * @return optional watcher instance
138146 */
139147 @ SuppressWarnings ("unchecked" )
140- static <T extends JUnitWatcher > Optional <T > getAttachedWatcher (Class <T > watcherType ) {
148+ static <W extends JUnitWatcher > Optional <W > getAttachedWatcher (Class <W > watcherType ) {
141149 if (RunWatcher .class .isAssignableFrom (watcherType )) {
142150 synchronized (runWatcherLoader ) {
143- for (RunWatcher watcher : runWatcherLoader ) {
151+ for (RunWatcher <?> watcher : runWatcherLoader ) {
144152 if (watcher .getClass () == watcherType ) {
145- return Optional .of ((T ) watcher );
153+ return Optional .of ((W ) watcher );
146154 }
147155 }
148156 }
0 commit comments