--- jsr166/src/test/tck/FutureTaskTest.java 2003/09/14 20:42:40 1.4 +++ jsr166/src/test/tck/FutureTaskTest.java 2003/09/20 18:20:07 1.5 @@ -30,38 +30,53 @@ public class FutureTaskTest extends JSR1 public void setException(Throwable t) { super.setException(t); } } - public void testConstructor(){ + /** + * + */ + public void testConstructor() { try { FutureTask task = new FutureTask(null); - fail("should throw"); + shouldThrow(); } catch(NullPointerException success) { } } - public void testConstructor2(){ + /** + * + */ + public void testConstructor2() { try { FutureTask task = new FutureTask(null, Boolean.TRUE); - fail("should throw"); + shouldThrow(); } catch(NullPointerException success) { } } - public void testIsDone(){ + /** + * + */ + public void testIsDone() { FutureTask task = new FutureTask( new NoOpCallable()); task.run(); assertTrue(task.isDone()); assertFalse(task.isCancelled()); } - public void testReset(){ + /** + * + */ + public void testReset() { MyFutureTask task = new MyFutureTask(new NoOpCallable()); task.run(); assertTrue(task.isDone()); assertTrue(task.reset()); } + /** + * + */ public void testResetAfterCancel() { MyFutureTask task = new MyFutureTask(new NoOpCallable()); assertTrue(task.cancel(false)); @@ -71,6 +86,9 @@ public class FutureTaskTest extends JSR1 assertFalse(task.reset()); } + /** + * + */ public void testSetDone() { MyFutureTask task = new MyFutureTask(new NoOpCallable()); task.setDone(); @@ -78,6 +96,9 @@ public class FutureTaskTest extends JSR1 assertFalse(task.isCancelled()); } + /** + * + */ public void testSetCancelled() { MyFutureTask task = new MyFutureTask(new NoOpCallable()); assertTrue(task.cancel(false)); @@ -86,6 +107,9 @@ public class FutureTaskTest extends JSR1 assertTrue(task.isCancelled()); } + /** + * + */ public void testSet() { MyFutureTask task = new MyFutureTask(new NoOpCallable()); task.set(one); @@ -93,27 +117,33 @@ public class FutureTaskTest extends JSR1 assertEquals(task.get(), one); } catch(Exception e) { - fail("unexpected exception"); + unexpectedException(); } } + /** + * + */ public void testSetException() { Exception nse = new NoSuchElementException(); MyFutureTask task = new MyFutureTask(new NoOpCallable()); task.setException(nse); try { Object x = task.get(); - fail("should throw"); + shouldThrow(); } catch(ExecutionException ee) { Throwable cause = ee.getCause(); assertEquals(cause, nse); } catch(Exception e) { - fail("unexpected exception"); + unexpectedException(); } } + /** + * + */ public void testCancelBeforeRun() { FutureTask task = new FutureTask( new NoOpCallable()); assertTrue(task.cancel(false)); @@ -122,6 +152,9 @@ public class FutureTaskTest extends JSR1 assertTrue(task.isCancelled()); } + /** + * + */ public void testCancelBeforeRun2() { FutureTask task = new FutureTask( new NoOpCallable()); assertTrue(task.cancel(true)); @@ -130,6 +163,9 @@ public class FutureTaskTest extends JSR1 assertTrue(task.isCancelled()); } + /** + * + */ public void testCancelAfterRun() { FutureTask task = new FutureTask( new NoOpCallable()); task.run(); @@ -138,12 +174,15 @@ public class FutureTaskTest extends JSR1 assertFalse(task.isCancelled()); } - public void testCancelInterrupt(){ + /** + * + */ + public void testCancelInterrupt() { FutureTask task = new FutureTask( new Callable() { public Object call() { try { Thread.sleep(MEDIUM_DELAY_MS); - threadFail("should throw"); + threadShouldThrow(); } catch (InterruptedException success) {} return Boolean.TRUE; @@ -151,19 +190,22 @@ public class FutureTaskTest extends JSR1 Thread t = new Thread(task); t.start(); - try{ + try { Thread.sleep(SHORT_DELAY_MS); assertTrue(task.cancel(true)); t.join(); assertTrue(task.isDone()); assertTrue(task.isCancelled()); } catch(InterruptedException e){ - fail("unexpected exception"); + unexpectedException(); } } - public void testCancelNoInterrupt(){ + /** + * + */ + public void testCancelNoInterrupt() { FutureTask task = new FutureTask( new Callable() { public Object call() { try { @@ -177,38 +219,41 @@ public class FutureTaskTest extends JSR1 Thread t = new Thread(task); t.start(); - try{ + try { Thread.sleep(SHORT_DELAY_MS); assertTrue(task.cancel(false)); t.join(); assertTrue(task.isDone()); assertTrue(task.isCancelled()); } catch(InterruptedException e){ - fail("unexpected exception"); + unexpectedException(); } } + /** + * + */ public void testGet1() { - final FutureTask ft = new FutureTask(new Callable(){ - public Object call(){ - try{ + final FutureTask ft = new FutureTask(new Callable() { + public Object call() { + try { Thread.sleep(MEDIUM_DELAY_MS); } catch(InterruptedException e){ - threadFail("unexpected exception"); + threadUnexpectedException(); } return Boolean.TRUE; } }); - Thread t = new Thread(new Runnable(){ - public void run(){ - try{ + Thread t = new Thread(new Runnable() { + public void run() { + try { ft.get(); } catch(Exception e){ - threadFail("unexpected exception"); + threadUnexpectedException(); } } }); - try{ + try { assertFalse(ft.isDone()); assertFalse(ft.isCancelled()); t.start(); @@ -218,33 +263,36 @@ public class FutureTaskTest extends JSR1 assertTrue(ft.isDone()); assertFalse(ft.isCancelled()); } catch(InterruptedException e){ - fail("unexpected exception"); + unexpectedException(); } } + /** + * + */ public void testTimedGet1() { - final FutureTask ft = new FutureTask(new Callable(){ - public Object call(){ - try{ + final FutureTask ft = new FutureTask(new Callable() { + public Object call() { + try { Thread.sleep(MEDIUM_DELAY_MS); } catch(InterruptedException e){ - threadFail("unexpected exception"); + threadUnexpectedException(); } return Boolean.TRUE; } }); - Thread t = new Thread(new Runnable(){ - public void run(){ - try{ + Thread t = new Thread(new Runnable() { + public void run() { + try { ft.get(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); } catch(TimeoutException success) { } catch(Exception e){ - threadFail("unexpected exception"); + threadUnexpectedException(); } } }); - try{ + try { assertFalse(ft.isDone()); assertFalse(ft.isCancelled()); t.start(); @@ -253,34 +301,37 @@ public class FutureTaskTest extends JSR1 assertTrue(ft.isDone()); assertFalse(ft.isCancelled()); } catch(InterruptedException e){ - fail("unexpected exception"); + unexpectedException(); } } - public void testGet_Cancellation(){ - final FutureTask ft = new FutureTask(new Callable(){ - public Object call(){ - try{ + /** + * + */ + public void testGet_Cancellation() { + final FutureTask ft = new FutureTask(new Callable() { + public Object call() { + try { Thread.sleep(MEDIUM_DELAY_MS); } catch(InterruptedException e){ - threadFail("unexpected exception"); + threadUnexpectedException(); } return Boolean.TRUE; } }); try { Thread.sleep(SHORT_DELAY_MS); - Thread t = new Thread(new Runnable(){ - public void run(){ - try{ + Thread t = new Thread(new Runnable() { + public void run() { + try { ft.get(); - threadFail("should throw"); + threadShouldThrow(); } catch(CancellationException success){ } catch(Exception e){ - threadFail("unexpected exception"); + threadUnexpectedException(); } } }); @@ -288,31 +339,34 @@ public class FutureTaskTest extends JSR1 ft.cancel(true); t.join(); } catch(InterruptedException success){ - fail("unexpected exception"); + unexpectedException(); } } - public void testGet_Cancellation2(){ - final FutureTask ft = new FutureTask(new Callable(){ - public Object call(){ - try{ + /** + * + */ + public void testGet_Cancellation2() { + final FutureTask ft = new FutureTask(new Callable() { + public Object call() { + try { Thread.sleep(SHORT_DELAY_MS); } catch(InterruptedException e) { - threadFail("unexpected exception"); + threadUnexpectedException(); } return Boolean.TRUE; } }); - try{ + try { Thread.sleep(SHORT_DELAY_MS); - Thread t = new Thread(new Runnable(){ - public void run(){ - try{ + Thread t = new Thread(new Runnable() { + public void run() { + try { ft.get(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); - threadFail("should throw"); + threadShouldThrow(); } catch(CancellationException success) {} catch(Exception e){ - threadFail("unexpected exception"); + threadUnexpectedException(); } } }); @@ -322,57 +376,66 @@ public class FutureTaskTest extends JSR1 Thread.sleep(SHORT_DELAY_MS); t.join(); } catch(InterruptedException ie){ - fail("unexpected exception"); + unexpectedException(); } } - public void testGet_ExecutionException(){ - final FutureTask ft = new FutureTask(new Callable(){ - public Object call(){ + /** + * + */ + public void testGet_ExecutionException() { + final FutureTask ft = new FutureTask(new Callable() { + public Object call() { int i = 5/0; return Boolean.TRUE; } }); - try{ + try { ft.run(); ft.get(); - fail("should throw"); + shouldThrow(); } catch(ExecutionException success){ } catch(Exception e){ - fail("unexpected exception"); + unexpectedException(); } } - public void testTimedGet_ExecutionException2(){ - final FutureTask ft = new FutureTask(new Callable(){ - public Object call(){ + /** + * + */ + public void testTimedGet_ExecutionException2() { + final FutureTask ft = new FutureTask(new Callable() { + public Object call() { int i = 5/0; return Boolean.TRUE; } }); - try{ + try { ft.run(); ft.get(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); - fail("should throw"); + shouldThrow(); } catch(ExecutionException success) { } catch(TimeoutException success) { } // unlikely but OK catch(Exception e){ - fail("unexpected exception"); + unexpectedException(); } } - public void testGet_InterruptedException(){ + /** + * + */ + public void testGet_InterruptedException() { final FutureTask ft = new FutureTask(new NoOpCallable()); - Thread t = new Thread(new Runnable(){ - public void run(){ - try{ + Thread t = new Thread(new Runnable() { + public void run() { + try { ft.get(); - threadFail("should throw"); + threadShouldThrow(); } catch(InterruptedException success){ } catch(Exception e){ - threadFail("unexpected exception"); + threadUnexpectedException(); } } }); @@ -382,20 +445,23 @@ public class FutureTaskTest extends JSR1 t.interrupt(); t.join(); } catch(Exception e){ - fail("unexpected exception"); + unexpectedException(); } } - public void testTimedGet_InterruptedException2(){ + /** + * + */ + public void testTimedGet_InterruptedException2() { final FutureTask ft = new FutureTask(new NoOpCallable()); - Thread t = new Thread(new Runnable(){ - public void run(){ - try{ + Thread t = new Thread(new Runnable() { + public void run() { + try { ft.get(LONG_DELAY_MS,TimeUnit.MILLISECONDS); - threadFail("should throw"); + threadShouldThrow(); } catch(InterruptedException success){} catch(Exception e){ - threadFail("unexpected exception"); + threadUnexpectedException(); } } }); @@ -405,18 +471,21 @@ public class FutureTaskTest extends JSR1 t.interrupt(); t.join(); } catch(Exception e){ - fail("unexpected exception"); + unexpectedException(); } } - public void testGet_TimeoutException(){ - try{ + /** + * + */ + public void testGet_TimeoutException() { + try { FutureTask ft = new FutureTask(new NoOpCallable()); ft.get(1,TimeUnit.MILLISECONDS); - fail("should throw"); + shouldThrow(); } catch(TimeoutException success){} catch(Exception success){ - fail("unexpected exception"); + unexpectedException(); } }