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.35 by jsr166, Mon Aug 3 19:07:51 2009 UTC vs.
Revision 1.39 by jsr166, Tue Nov 17 21:51:45 2009 UTC

# Line 9 | Line 9
9   import junit.framework.*;
10   import java.util.*;
11   import java.util.concurrent.*;
12 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
13   import java.io.*;
14   import java.security.*;
15  
# Line 288 | Line 289 | public class JSR166TestCase extends Test
289       * threadFail with message "should throw exception"
290       */
291      public void threadShouldThrow() {
292 <        try {
293 <            threadFailed = true;
293 <            fail("should throw exception");
294 <        } catch (AssertionFailedError e) {
295 <            e.printStackTrace();
296 <            throw e;
297 <        }
292 >        threadFailed = true;
293 >        fail("should throw exception");
294      }
295  
296      /**
# Line 320 | Line 316 | public class JSR166TestCase extends Test
316      public void joinPool(ExecutorService exec) {
317          try {
318              exec.shutdown();
319 <            assertTrue(exec.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
319 >            assertTrue(exec.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
320          } catch (SecurityException ok) {
321              // Allowed in case test doesn't have privs
322          } catch (InterruptedException ie) {
# Line 343 | Line 339 | public class JSR166TestCase extends Test
339          fail("Unexpected exception");
340      }
341  
342 +    /**
343 +     * fail with message "Unexpected exception", with argument
344 +     */
345 +    public void unexpectedException(Throwable ex) {
346 +        ex.printStackTrace();
347 +        fail("Unexpected exception: " + ex);
348 +    }
349 +
350  
351      /**
352       * The number of elements to place in collections, arrays, etc.
# Line 391 | Line 395 | public class JSR166TestCase extends Test
395          public void refresh() {}
396      }
397  
398 +    /**
399 +     * Sleep until the timeout has elapsed, or interrupted.
400 +     * Does <em>NOT</em> throw InterruptedException.
401 +     */
402 +    void sleepTillInterrupted(long timeoutMillis) {
403 +        try {
404 +            Thread.sleep(timeoutMillis);
405 +        } catch (InterruptedException wakeup) {
406 +        }
407 +    }
408 +
409 +    /**
410 +     * Returns a new started Thread running the given runnable.
411 +     */
412 +    Thread newStartedThread(Runnable runnable) {
413 +        Thread t = new Thread(runnable);
414 +        t.start();
415 +        return t;
416 +    }
417  
418      // Some convenient Runnable classes
419  
# Line 543 | Line 566 | public class JSR166TestCase extends Test
566              try {
567                  Thread.sleep(SMALL_DELAY_MS);
568                  done = true;
569 <            } catch (Exception e) {
569 >            } catch (InterruptedException ok) {
570              }
571          }
572      }
# Line 554 | Line 577 | public class JSR166TestCase extends Test
577              try {
578                  Thread.sleep(MEDIUM_DELAY_MS);
579                  done = true;
580 <            } catch (Exception e) {
580 >            } catch (InterruptedException ok) {
581              }
582          }
583      }
# Line 565 | Line 588 | public class JSR166TestCase extends Test
588              try {
589                  Thread.sleep(LONG_DELAY_MS);
590                  done = true;
591 <            } catch (Exception e) {
591 >            } catch (InterruptedException ok) {
592              }
593          }
594      }
# Line 583 | Line 606 | public class JSR166TestCase extends Test
606              try {
607                  Thread.sleep(SMALL_DELAY_MS);
608                  done = true;
609 <            } catch (Exception e) {
609 >            } catch (InterruptedException ok) {
610              }
611              return Boolean.TRUE;
612          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines