--- jsr166/src/test/tck/ExchangerTest.java 2011/05/29 06:48:42 1.20 +++ jsr166/src/test/tck/ExchangerTest.java 2021/01/27 01:57:24 1.27 @@ -6,15 +6,19 @@ * Pat Fisher, Mike Judd. */ -import junit.framework.*; -import java.util.*; -import java.util.concurrent.*; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Exchanger; +import java.util.concurrent.TimeoutException; + +import junit.framework.Test; +import junit.framework.TestSuite; + public class ExchangerTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { return new TestSuite(ExchangerTest.class); @@ -24,7 +28,7 @@ public class ExchangerTest extends JSR16 * exchange exchanges objects across two threads */ public void testExchange() { - final Exchanger e = new Exchanger(); + final Exchanger e = new Exchanger<>(); Thread t1 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { assertSame(one, e.exchange(two)); @@ -44,7 +48,7 @@ public class ExchangerTest extends JSR16 * timed exchange exchanges objects across two threads */ public void testTimedExchange() { - final Exchanger e = new Exchanger(); + final Exchanger e = new Exchanger<>(); Thread t1 = newStartedThread(new CheckedRunnable() { public void realRun() throws Exception { assertSame(one, e.exchange(two, LONG_DELAY_MS, MILLISECONDS)); @@ -61,10 +65,10 @@ public class ExchangerTest extends JSR16 } /** - * interrupt during wait for exchange throws IE + * interrupt during wait for exchange throws InterruptedException */ public void testExchange_InterruptedException() { - final Exchanger e = new Exchanger(); + final Exchanger e = new Exchanger<>(); final CountDownLatch threadStarted = new CountDownLatch(1); Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { @@ -78,10 +82,10 @@ public class ExchangerTest extends JSR16 } /** - * interrupt during wait for timed exchange throws IE + * interrupt during wait for timed exchange throws InterruptedException */ public void testTimedExchange_InterruptedException() { - final Exchanger e = new Exchanger(); + final Exchanger e = new Exchanger<>(); final CountDownLatch threadStarted = new CountDownLatch(1); Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws Exception { @@ -98,7 +102,7 @@ public class ExchangerTest extends JSR16 * timeout during wait for timed exchange throws TimeoutException */ public void testExchange_TimeoutException() { - final Exchanger e = new Exchanger(); + final Exchanger e = new Exchanger<>(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws Exception { long startTime = System.nanoTime(); @@ -116,7 +120,7 @@ public class ExchangerTest extends JSR16 * If one exchanging thread is interrupted, another succeeds. */ public void testReplacementAfterExchange() { - final Exchanger e = new Exchanger(); + final Exchanger e = new Exchanger<>(); final CountDownLatch exchanged = new CountDownLatch(2); final CountDownLatch interrupted = new CountDownLatch(1); Thread t1 = newStartedThread(new CheckedInterruptedRunnable() { @@ -129,12 +133,12 @@ public class ExchangerTest extends JSR16 public void realRun() throws InterruptedException { assertSame(one, e.exchange(two)); exchanged.countDown(); - interrupted.await(); + await(interrupted); assertSame(three, e.exchange(one)); }}); Thread t3 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - interrupted.await(); + await(interrupted); assertSame(one, e.exchange(three)); }});