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.34 by jsr166, Fri Jul 31 23:53:23 2009 UTC vs.
Revision 1.35 by jsr166, Mon Aug 3 19:07:51 2009 UTC

# Line 394 | Line 394 | public class JSR166TestCase extends Test
394  
395      // Some convenient Runnable classes
396  
397 +    abstract class CheckedRunnable implements Runnable {
398 +        abstract void realRun() throws Throwable;
399 +
400 +        public final void run() {
401 +            try {
402 +                realRun();
403 +            } catch (Throwable t) {
404 +                threadUnexpectedException(t);
405 +            }
406 +        }
407 +    }
408 +
409 +    abstract class CheckedInterruptedRunnable implements Runnable {
410 +        abstract void realRun() throws Throwable;
411 +
412 +        public final void run() {
413 +            try {
414 +                realRun();
415 +                threadShouldThrow();
416 +            } catch (InterruptedException success) {
417 +            } catch (Throwable t) {
418 +                threadUnexpectedException(t);
419 +            }
420 +        }
421 +    }
422 +
423 +    abstract class CheckedCallable<T> implements Callable<T> {
424 +        abstract T realCall() throws Throwable;
425 +
426 +        public final T call() {
427 +            try {
428 +                return realCall();
429 +            } catch (Throwable t) {
430 +                threadUnexpectedException(t);
431 +                return null;
432 +            }
433 +        }
434 +    }
435 +
436      static class NoOpRunnable implements Runnable {
437          public void run() {}
438      }
# Line 416 | Line 455 | public class JSR166TestCase extends Test
455          public Integer call() { return one; }
456      }
457  
458 <    class ShortRunnable implements Runnable {
459 <        public void run() {
460 <            try {
422 <                Thread.sleep(SHORT_DELAY_MS);
423 <            }
424 <            catch (Exception e) {
425 <                threadUnexpectedException(e);
426 <            }
458 >    class ShortRunnable extends CheckedRunnable {
459 >        void realRun() throws Throwable {
460 >            Thread.sleep(SHORT_DELAY_MS);
461          }
462      }
463  
464 <    class ShortInterruptedRunnable implements Runnable {
465 <        public void run() {
466 <            try {
433 <                Thread.sleep(SHORT_DELAY_MS);
434 <                threadShouldThrow();
435 <            }
436 <            catch (InterruptedException success) {
437 <            }
464 >    class ShortInterruptedRunnable extends CheckedInterruptedRunnable {
465 >        void realRun() throws InterruptedException {
466 >            Thread.sleep(SHORT_DELAY_MS);
467          }
468      }
469  
470 <    class SmallRunnable implements Runnable {
471 <        public void run() {
472 <            try {
444 <                Thread.sleep(SMALL_DELAY_MS);
445 <            }
446 <            catch (Exception e) {
447 <                threadUnexpectedException(e);
448 <            }
470 >    class SmallRunnable extends CheckedRunnable {
471 >        void realRun() throws Throwable {
472 >            Thread.sleep(SMALL_DELAY_MS);
473          }
474      }
475  
476 <    class SmallPossiblyInterruptedRunnable implements Runnable {
477 <        public void run() {
476 >    class SmallPossiblyInterruptedRunnable extends CheckedRunnable {
477 >        void realRun() {
478              try {
479                  Thread.sleep(SMALL_DELAY_MS);
480              }
481 <            catch (Exception e) {
481 >            catch (InterruptedException ok) {
482              }
483          }
484      }
485  
486 <    class SmallCallable implements Callable {
487 <        public Object call() {
488 <            try {
465 <                Thread.sleep(SMALL_DELAY_MS);
466 <            }
467 <            catch (Exception e) {
468 <                threadUnexpectedException(e);
469 <            }
486 >    class SmallCallable extends CheckedCallable {
487 >        Object realCall() throws Throwable {
488 >            Thread.sleep(SMALL_DELAY_MS);
489              return Boolean.TRUE;
490          }
491      }
492  
493 <    class SmallInterruptedRunnable implements Runnable {
494 <        public void run() {
495 <            try {
477 <                Thread.sleep(SMALL_DELAY_MS);
478 <                threadShouldThrow();
479 <            }
480 <            catch (InterruptedException success) {
481 <            }
493 >    class SmallInterruptedRunnable extends CheckedInterruptedRunnable {
494 >        void realRun() throws InterruptedException {
495 >            Thread.sleep(SMALL_DELAY_MS);
496          }
497      }
498  
499 <
500 <    class MediumRunnable implements Runnable {
501 <        public void run() {
488 <            try {
489 <                Thread.sleep(MEDIUM_DELAY_MS);
490 <            }
491 <            catch (Exception e) {
492 <                threadUnexpectedException(e);
493 <            }
499 >    class MediumRunnable extends CheckedRunnable {
500 >        void realRun() throws Throwable {
501 >            Thread.sleep(MEDIUM_DELAY_MS);
502          }
503      }
504  
505 <    class MediumInterruptedRunnable implements Runnable {
506 <        public void run() {
507 <            try {
500 <                Thread.sleep(MEDIUM_DELAY_MS);
501 <                threadShouldThrow();
502 <            }
503 <            catch (InterruptedException success) {
504 <            }
505 >    class MediumInterruptedRunnable extends CheckedInterruptedRunnable {
506 >        void realRun() throws InterruptedException {
507 >            Thread.sleep(MEDIUM_DELAY_MS);
508          }
509      }
510  
511 <    class MediumPossiblyInterruptedRunnable implements Runnable {
512 <        public void run() {
511 >    class MediumPossiblyInterruptedRunnable extends CheckedRunnable {
512 >        void realRun() {
513              try {
514                  Thread.sleep(MEDIUM_DELAY_MS);
515              }
516 <            catch (InterruptedException success) {
516 >            catch (InterruptedException ok) {
517              }
518          }
519      }
520  
521 <    class LongPossiblyInterruptedRunnable implements Runnable {
522 <        public void run() {
521 >    class LongPossiblyInterruptedRunnable extends CheckedRunnable {
522 >        void realRun() {
523              try {
524                  Thread.sleep(LONG_DELAY_MS);
525              }
526 <            catch (InterruptedException success) {
526 >            catch (InterruptedException ok) {
527              }
528          }
529      }
# Line 591 | Line 594 | public class JSR166TestCase extends Test
594       * For use as RejectedExecutionHandler in constructors
595       */
596      static class NoOpREHandler implements RejectedExecutionHandler {
597 <        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){}
597 >        public void rejectedExecution(Runnable r,
598 >                                      ThreadPoolExecutor executor) {}
599      }
600  
597
601   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines