ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.39 by jsr166, Tue Nov 17 21:51:45 2009 UTC vs.
Revision 1.40 by jsr166, Fri Nov 20 00:58:01 2009 UTC

# Line 294 | Line 294 | public class JSR166TestCase extends Test
294      }
295  
296      /**
297 +     * threadFail with message "should throw" + exceptionName
298 +     */
299 +    public void threadShouldThrow(String exceptionName) {
300 +        threadFailed = true;
301 +        fail("should throw " + exceptionName);
302 +    }
303 +
304 +    /**
305       * threadFail with message "Unexpected exception"
306       */
307      public void threadUnexpectedException() {
# Line 333 | Line 341 | public class JSR166TestCase extends Test
341      }
342  
343      /**
344 +     * fail with message "should throw " + exceptionName
345 +     */
346 +    public void shouldThrow(String exceptionName) {
347 +        fail("Should throw " + exceptionName);
348 +    }
349 +
350 +    /**
351       * fail with message "Unexpected exception"
352       */
353      public void unexpectedException() {
# Line 429 | Line 444 | public class JSR166TestCase extends Test
444          }
445      }
446  
447 +    abstract class RunnableShouldThrow implements Runnable {
448 +        abstract void realRun() throws Throwable;
449 +
450 +        final Class<?> exceptionClass;
451 +
452 +        <T extends Throwable> RunnableShouldThrow(Class<T> exceptionClass) {
453 +            this.exceptionClass = exceptionClass;
454 +        }
455 +
456 +        public final void run() {
457 +            try {
458 +                realRun();
459 +                threadShouldThrow(exceptionClass.getSimpleName());
460 +            } catch (InterruptedException success) {
461 +            } catch (Throwable t) {
462 +                if (! exceptionClass.isInstance(t))
463 +                    threadUnexpectedException(t);
464 +            }
465 +        }
466 +    }
467 +
468 +    abstract class ThreadShouldThrow extends Thread {
469 +        abstract void realRun() throws Throwable;
470 +
471 +        final Class<?> exceptionClass;
472 +
473 +        <T extends Throwable> ThreadShouldThrow(Class<T> exceptionClass) {
474 +            this.exceptionClass = exceptionClass;
475 +        }
476 +
477 +        public final void run() {
478 +            try {
479 +                realRun();
480 +                threadShouldThrow(exceptionClass.getSimpleName());
481 +            } catch (InterruptedException success) {
482 +            } catch (Throwable t) {
483 +                if (! exceptionClass.isInstance(t))
484 +                    threadUnexpectedException(t);
485 +            }
486 +        }
487 +    }
488 +
489      abstract class CheckedInterruptedRunnable implements Runnable {
490          abstract void realRun() throws Throwable;
491  
492          public final void run() {
493              try {
494                  realRun();
495 <                threadShouldThrow();
495 >                threadShouldThrow("InterruptedException");
496              } catch (InterruptedException success) {
497              } catch (Throwable t) {
498                  threadUnexpectedException(t);
# Line 451 | Line 508 | public class JSR166TestCase extends Test
508                  return realCall();
509              } catch (Throwable t) {
510                  threadUnexpectedException(t);
454                return null;
511              }
512 +            return null;
513 +        }
514 +    }
515 +
516 +    abstract class CheckedInterruptedCallable<T> implements Callable<T> {
517 +        abstract T realCall() throws Throwable;
518 +
519 +        public final T call() {
520 +            try {
521 +                T result = realCall();
522 +                threadShouldThrow("InterruptedException");
523 +                return result;
524 +            } catch (InterruptedException success) {
525 +            } catch (Throwable t) {
526 +                threadUnexpectedException(t);
527 +            }
528 +            return null;
529          }
530      }
531  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines