--- jsr166/src/test/tck/JSR166TestCase.java 2009/08/03 19:07:51 1.35 +++ jsr166/src/test/tck/JSR166TestCase.java 2009/11/17 21:51:45 1.39 @@ -9,6 +9,7 @@ import junit.framework.*; import java.util.*; import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.*; import java.security.*; @@ -288,13 +289,8 @@ public class JSR166TestCase extends Test * threadFail with message "should throw exception" */ public void threadShouldThrow() { - try { - threadFailed = true; - fail("should throw exception"); - } catch (AssertionFailedError e) { - e.printStackTrace(); - throw e; - } + threadFailed = true; + fail("should throw exception"); } /** @@ -320,7 +316,7 @@ public class JSR166TestCase extends Test public void joinPool(ExecutorService exec) { try { exec.shutdown(); - assertTrue(exec.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); + assertTrue(exec.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); } catch (SecurityException ok) { // Allowed in case test doesn't have privs } catch (InterruptedException ie) { @@ -343,6 +339,14 @@ public class JSR166TestCase extends Test fail("Unexpected exception"); } + /** + * fail with message "Unexpected exception", with argument + */ + public void unexpectedException(Throwable ex) { + ex.printStackTrace(); + fail("Unexpected exception: " + ex); + } + /** * The number of elements to place in collections, arrays, etc. @@ -391,6 +395,25 @@ public class JSR166TestCase extends Test public void refresh() {} } + /** + * Sleep until the timeout has elapsed, or interrupted. + * Does NOT throw InterruptedException. + */ + void sleepTillInterrupted(long timeoutMillis) { + try { + Thread.sleep(timeoutMillis); + } catch (InterruptedException wakeup) { + } + } + + /** + * Returns a new started Thread running the given runnable. + */ + Thread newStartedThread(Runnable runnable) { + Thread t = new Thread(runnable); + t.start(); + return t; + } // Some convenient Runnable classes @@ -543,7 +566,7 @@ public class JSR166TestCase extends Test try { Thread.sleep(SMALL_DELAY_MS); done = true; - } catch (Exception e) { + } catch (InterruptedException ok) { } } } @@ -554,7 +577,7 @@ public class JSR166TestCase extends Test try { Thread.sleep(MEDIUM_DELAY_MS); done = true; - } catch (Exception e) { + } catch (InterruptedException ok) { } } } @@ -565,7 +588,7 @@ public class JSR166TestCase extends Test try { Thread.sleep(LONG_DELAY_MS); done = true; - } catch (Exception e) { + } catch (InterruptedException ok) { } } } @@ -583,7 +606,7 @@ public class JSR166TestCase extends Test try { Thread.sleep(SMALL_DELAY_MS); done = true; - } catch (Exception e) { + } catch (InterruptedException ok) { } return Boolean.TRUE; }