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.38 by jsr166, Wed Aug 5 00:43:59 2009 UTC vs.
Revision 1.41 by jsr166, Fri Nov 20 06:27:39 2009 UTC

# Line 90 | Line 90 | public class JSR166TestCase extends Test
90      /**
91       * Runs all JSR166 unit tests using junit.textui.TestRunner
92       */
93 <    public static void main (String[] args) {
93 >    public static void main(String[] args) {
94          int iters = 1;
95          if (args.length > 0)
96              iters = Integer.parseInt(args[0]);
97          Test s = suite();
98          for (int i = 0; i < iters; ++i) {
99 <            junit.textui.TestRunner.run (s);
99 >            junit.textui.TestRunner.run(s);
100              System.gc();
101              System.runFinalization();
102          }
# Line 106 | Line 106 | public class JSR166TestCase extends Test
106      /**
107       * Collects all JSR166 unit tests as one suite
108       */
109 <    public static Test suite ( ) {
109 >    public static Test suite() {
110          TestSuite suite = new TestSuite("JSR166 Unit Tests");
111  
112          suite.addTest(new TestSuite(ForkJoinPoolTest.class));
# 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  
# Line 566 | Line 639 | public class JSR166TestCase extends Test
639              try {
640                  Thread.sleep(SMALL_DELAY_MS);
641                  done = true;
642 <            } catch (Exception e) {
642 >            } catch (InterruptedException ok) {
643              }
644          }
645      }
# Line 577 | Line 650 | public class JSR166TestCase extends Test
650              try {
651                  Thread.sleep(MEDIUM_DELAY_MS);
652                  done = true;
653 <            } catch (Exception e) {
653 >            } catch (InterruptedException ok) {
654              }
655          }
656      }
# Line 588 | Line 661 | public class JSR166TestCase extends Test
661              try {
662                  Thread.sleep(LONG_DELAY_MS);
663                  done = true;
664 <            } catch (Exception e) {
664 >            } catch (InterruptedException ok) {
665              }
666          }
667      }
# Line 606 | Line 679 | public class JSR166TestCase extends Test
679              try {
680                  Thread.sleep(SMALL_DELAY_MS);
681                  done = true;
682 <            } catch (Exception e) {
682 >            } catch (InterruptedException ok) {
683              }
684              return Boolean.TRUE;
685          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines