--- jsr166/src/test/tck/JSR166TestCase.java 2009/11/17 21:51:45 1.39 +++ jsr166/src/test/tck/JSR166TestCase.java 2009/11/20 00:58:01 1.40 @@ -294,6 +294,14 @@ public class JSR166TestCase extends Test } /** + * threadFail with message "should throw" + exceptionName + */ + public void threadShouldThrow(String exceptionName) { + threadFailed = true; + fail("should throw " + exceptionName); + } + + /** * threadFail with message "Unexpected exception" */ public void threadUnexpectedException() { @@ -333,6 +341,13 @@ public class JSR166TestCase extends Test } /** + * fail with message "should throw " + exceptionName + */ + public void shouldThrow(String exceptionName) { + fail("Should throw " + exceptionName); + } + + /** * fail with message "Unexpected exception" */ public void unexpectedException() { @@ -429,13 +444,55 @@ public class JSR166TestCase extends Test } } + abstract class RunnableShouldThrow implements Runnable { + abstract void realRun() throws Throwable; + + final Class exceptionClass; + + RunnableShouldThrow(Class exceptionClass) { + this.exceptionClass = exceptionClass; + } + + public final void run() { + try { + realRun(); + threadShouldThrow(exceptionClass.getSimpleName()); + } catch (InterruptedException success) { + } catch (Throwable t) { + if (! exceptionClass.isInstance(t)) + threadUnexpectedException(t); + } + } + } + + abstract class ThreadShouldThrow extends Thread { + abstract void realRun() throws Throwable; + + final Class exceptionClass; + + ThreadShouldThrow(Class exceptionClass) { + this.exceptionClass = exceptionClass; + } + + public final void run() { + try { + realRun(); + threadShouldThrow(exceptionClass.getSimpleName()); + } catch (InterruptedException success) { + } catch (Throwable t) { + if (! exceptionClass.isInstance(t)) + threadUnexpectedException(t); + } + } + } + abstract class CheckedInterruptedRunnable implements Runnable { abstract void realRun() throws Throwable; public final void run() { try { realRun(); - threadShouldThrow(); + threadShouldThrow("InterruptedException"); } catch (InterruptedException success) { } catch (Throwable t) { threadUnexpectedException(t); @@ -451,8 +508,24 @@ public class JSR166TestCase extends Test return realCall(); } catch (Throwable t) { threadUnexpectedException(t); - return null; } + return null; + } + } + + abstract class CheckedInterruptedCallable implements Callable { + abstract T realCall() throws Throwable; + + public final T call() { + try { + T result = realCall(); + threadShouldThrow("InterruptedException"); + return result; + } catch (InterruptedException success) { + } catch (Throwable t) { + threadUnexpectedException(t); + } + return null; } }