--- jsr166/src/test/tck/TimeUnitTest.java 2003/09/14 20:42:41 1.3 +++ jsr166/src/test/tck/TimeUnitTest.java 2003/09/20 18:20:08 1.4 @@ -19,6 +19,9 @@ public class TimeUnitTest extends JSR166 return new TestSuite(TimeUnitTest.class); } + /** + * + */ public void testConvert() { for (long t = 0; t < 10; ++t) { assertEquals(t, @@ -72,6 +75,9 @@ public class TimeUnitTest extends JSR166 } } + /** + * + */ public void testToNanos() { for (long t = 0; t < 10; ++t) { assertEquals(1000000000 * t, @@ -86,6 +92,9 @@ public class TimeUnitTest extends JSR166 } } + /** + * + */ public void testToMicros() { for (long t = 0; t < 10; ++t) { assertEquals(1000000 * t, @@ -100,6 +109,9 @@ public class TimeUnitTest extends JSR166 } } + /** + * + */ public void testToMillis() { for (long t = 0; t < 10; ++t) { assertEquals(1000 * t, @@ -114,6 +126,9 @@ public class TimeUnitTest extends JSR166 } } + /** + * + */ public void testToSeconds() { for (long t = 0; t < 10; ++t) { assertEquals(t, @@ -129,6 +144,9 @@ public class TimeUnitTest extends JSR166 } + /** + * + */ public void testConvertSaturate() { assertEquals(Long.MAX_VALUE, TimeUnit.NANOSECONDS.convert(Long.MAX_VALUE / 2, @@ -139,6 +157,9 @@ public class TimeUnitTest extends JSR166 } + /** + * + */ public void testToNanosSaturate() { assertEquals(Long.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(Long.MAX_VALUE / 2)); @@ -148,6 +169,9 @@ public class TimeUnitTest extends JSR166 } + /** + * + */ public void testToString() { String s = TimeUnit.SECONDS.toString(); assertTrue(s.indexOf("econd") >= 0); @@ -158,6 +182,9 @@ public class TimeUnitTest extends JSR166 * Timed wait without holding lock throws * IllegalMonitorStateException */ + /** + * + */ public void testTimedWait_IllegalMonitorException() { //created a new thread with anonymous runnable @@ -167,10 +194,10 @@ public class TimeUnitTest extends JSR166 TimeUnit tu = TimeUnit.MILLISECONDS; try { tu.timedWait(o,LONG_DELAY_MS); - fail("should throw"); + threadShouldThrow(); } catch (InterruptedException ie) { - fail("should not throw IE here"); + threadUnexpectedException(); } catch(IllegalMonitorStateException success) { } @@ -183,7 +210,7 @@ public class TimeUnitTest extends JSR166 t.interrupt(); t.join(); } catch(Exception e) { - fail("Unexpected exception"); + unexpectedException(); } } @@ -193,6 +220,9 @@ public class TimeUnitTest extends JSR166 * Note: This does not throw IllegalMonitorException since timeWait * is synchronized on o */ + /** + * + */ public void testTimedWait() { Thread t = new Thread(new Runnable() { public void run() { @@ -203,11 +233,11 @@ public class TimeUnitTest extends JSR166 synchronized(o) { tu.timedWait(o,MEDIUM_DELAY_MS); } - fail("should throw"); + threadShouldThrow(); } catch(InterruptedException success) {} catch(IllegalMonitorStateException failure) { - fail("should not throw"); + threadUnexpectedException(); } } }); @@ -217,7 +247,7 @@ public class TimeUnitTest extends JSR166 t.interrupt(); t.join(); } catch(Exception e) { - fail("Unexpected exception"); + unexpectedException(); } } @@ -226,6 +256,9 @@ public class TimeUnitTest extends JSR166 * timedJoin will throw InterruptedException. * Thread t waits on timedJoin while the main thread interrupts it. */ + /** + * + */ public void testTimedJoin() { Thread t = new Thread(new Runnable() { public void run() { @@ -233,14 +266,14 @@ public class TimeUnitTest extends JSR166 try { Thread s = new Thread(new Runnable() { public void run() { - try{ + try { Thread.sleep(MEDIUM_DELAY_MS); - }catch(InterruptedException success){} + } catch(InterruptedException success){} } }); s.start(); tu.timedJoin(s,MEDIUM_DELAY_MS); - fail("should throw"); + threadShouldThrow(); } catch(Exception e) {} } @@ -251,7 +284,7 @@ public class TimeUnitTest extends JSR166 t.interrupt(); t.join(); } catch(Exception e) { - fail("Unexpected exception"); + unexpectedException(); } } @@ -259,6 +292,9 @@ public class TimeUnitTest extends JSR166 * timedSleep will throw InterruptedException. * Thread t waits on timedSleep while the main thread interrupts it. */ + /** + * + */ public void testTimedSleep() { //created a new thread with anonymous runnable @@ -267,7 +303,7 @@ public class TimeUnitTest extends JSR166 TimeUnit tu = TimeUnit.MILLISECONDS; try { tu.sleep(MEDIUM_DELAY_MS); - fail("should throw"); + threadShouldThrow(); } catch(InterruptedException success) {} } @@ -278,10 +314,13 @@ public class TimeUnitTest extends JSR166 t.interrupt(); t.join(); } catch(Exception e) { - fail("Unexpected exception"); + unexpectedException(); } } + /** + * + */ public void testSerialization() { TimeUnit q = TimeUnit.MILLISECONDS; @@ -298,7 +337,7 @@ public class TimeUnitTest extends JSR166 assertEquals(q.toString(), r.toString()); } catch(Exception e){ e.printStackTrace(); - fail("unexpected exception"); + unexpectedException(); } }