--- jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2009/11/18 16:51:26 1.5 +++ jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2009/11/20 06:33:25 1.6 @@ -14,10 +14,10 @@ import java.util.*; public class ThreadPoolExecutorSubclassTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } public static Test suite() { - return new TestSuite(ThreadPoolExecutorTest.class); + return new TestSuite(ThreadPoolExecutorSubclassTest.class); } static class CustomTask implements RunnableFuture { @@ -29,8 +29,13 @@ public class ThreadPoolExecutorSubclassT V result; Thread thread; Exception exception; - CustomTask(Callable c) { callable = c; } - CustomTask(final Runnable r, final V res) { callable = new Callable() { + CustomTask(Callable c) { + if (c == null) throw new NullPointerException(); + callable = c; + } + CustomTask(final Runnable r, final V res) { + if (r == null) throw new NullPointerException(); + callable = new Callable() { public V call() throws Exception { r.run(); return res; }}; } public boolean isDone() { @@ -995,10 +1000,8 @@ public class ThreadPoolExecutorSubclassT * setCorePoolSize of negative value throws IllegalArgumentException */ public void testCorePoolSizeIllegalArgumentException() { - ThreadPoolExecutor tpe = null; - try { - tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch (Exception e) {} + ThreadPoolExecutor tpe = + new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); try { tpe.setCorePoolSize(-1); shouldThrow(); @@ -1276,8 +1279,8 @@ public class ThreadPoolExecutorSubclassT l.add(new NPETask()); List> result = e.invokeAll(l); assertEquals(1, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - it.next().get(); + for (Future future : result) + future.get(); shouldThrow(); } catch (ExecutionException success) { } finally { @@ -1296,10 +1299,8 @@ public class ThreadPoolExecutorSubclassT l.add(new StringTask()); List> result = e.invokeAll(l); assertEquals(2, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - assertSame(TEST_STRING, it.next().get()); - shouldThrow(); - } catch (ExecutionException success) { + for (Future future : result) + assertSame(TEST_STRING, future.get()); } finally { joinPool(e); } @@ -1395,8 +1396,6 @@ public class ThreadPoolExecutorSubclassT l.add(new StringTask()); String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); assertSame(TEST_STRING, result); - shouldThrow(); - } catch (ExecutionException success) { } finally { joinPool(e); } @@ -1472,10 +1471,11 @@ public class ThreadPoolExecutorSubclassT l.add(new NPETask()); List> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); assertEquals(1, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - it.next().get(); + for (Future future : result) + future.get(); shouldThrow(); } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); } @@ -1492,9 +1492,8 @@ public class ThreadPoolExecutorSubclassT l.add(new StringTask()); List> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); assertEquals(2, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - assertSame(TEST_STRING, it.next().get()); - shouldThrow(); + for (Future future : result) + assertSame(TEST_STRING, future.get()); } catch (ExecutionException success) { } finally { joinPool(e); @@ -1534,7 +1533,6 @@ public class ThreadPoolExecutorSubclassT public void testFailingThreadFactory() throws InterruptedException { ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new FailingThreadFactory()); try { - ArrayList> l = new ArrayList>(); for (int k = 0; k < 100; ++k) { e.execute(new NoOpRunnable()); }