--- jsr166/src/test/tck/ExecutorsTest.java 2003/09/25 11:02:41 1.5 +++ jsr166/src/test/tck/ExecutorsTest.java 2003/10/05 23:00:40 1.7 @@ -21,13 +21,6 @@ public class ExecutorsTest extends JSR16 private static final String TEST_STRING = "a test string"; - private static class MyTask implements Runnable { - public void run() { completed = true; } - public boolean isCompleted() { return completed; } - public void reset() { completed = false; } - private boolean completed = false; - } - private static class StringTask implements Callable { public String call() { return TEST_STRING; } } @@ -79,15 +72,6 @@ public class ExecutorsTest extends JSR16 }; /** - * For use as ThreadFactory in constructors - */ - static class MyThreadFactory implements ThreadFactory{ - public Thread newThread(Runnable r){ - return new Thread(r); - } - } - - /** * A newCachedThreadPool can execute runnables */ public void testNewCachedThreadPool1() { @@ -102,7 +86,7 @@ public class ExecutorsTest extends JSR16 * A newCachedThreadPool with given ThreadFactory can execute runnables */ public void testNewCachedThreadPool2() { - ExecutorService e = Executors.newCachedThreadPool(new MyThreadFactory()); + ExecutorService e = Executors.newCachedThreadPool(new SimpleThreadFactory()); e.execute(new NoOpRunnable()); e.execute(new NoOpRunnable()); e.execute(new NoOpRunnable()); @@ -137,7 +121,7 @@ public class ExecutorsTest extends JSR16 * A new SingleThreadExecutor with given ThreadFactory can execute runnables */ public void testNewSingleThreadExecutor2() { - ExecutorService e = Executors.newSingleThreadExecutor(new MyThreadFactory()); + ExecutorService e = Executors.newSingleThreadExecutor(new SimpleThreadFactory()); e.execute(new NoOpRunnable()); e.execute(new NoOpRunnable()); e.execute(new NoOpRunnable()); @@ -171,7 +155,7 @@ public class ExecutorsTest extends JSR16 * A new newFixedThreadPool with given ThreadFactory can execute runnables */ public void testNewFixedThreadPool2() { - ExecutorService e = Executors.newFixedThreadPool(2, new MyThreadFactory()); + ExecutorService e = Executors.newFixedThreadPool(2, new SimpleThreadFactory()); e.execute(new NoOpRunnable()); e.execute(new NoOpRunnable()); e.execute(new NoOpRunnable()); @@ -205,14 +189,14 @@ public class ExecutorsTest extends JSR16 /** * execute of runnable runs it to completion */ - public void testExecuteRunnable () { + public void testExecuteRunnable() { try { Executor e = new DirectExecutor(); - MyTask task = new MyTask(); - assertFalse(task.isCompleted()); + TrackedShortRunnable task = new TrackedShortRunnable(); + assertFalse(task.done); Future future = Executors.execute(e, task, TEST_STRING); String result = future.get(); - assertTrue(task.isCompleted()); + assertTrue(task.done); assertSame(TEST_STRING, result); } catch (ExecutionException ex) { @@ -226,13 +210,13 @@ public class ExecutorsTest extends JSR16 /** * invoke of a runnable runs it to completion */ - public void testInvokeRunnable () { + public void testInvokeRunnable() { try { Executor e = new DirectExecutor(); - MyTask task = new MyTask(); - assertFalse(task.isCompleted()); + TrackedShortRunnable task = new TrackedShortRunnable(); + assertFalse(task.done); Executors.invoke(e, task); - assertTrue(task.isCompleted()); + assertTrue(task.done); } catch (ExecutionException ex) { unexpectedException(); @@ -245,7 +229,7 @@ public class ExecutorsTest extends JSR16 /** * execute of a callable runs it to completion */ - public void testExecuteCallable () { + public void testExecuteCallable() { try { Executor e = new DirectExecutor(); Future future = Executors.execute(e, new StringTask()); @@ -263,7 +247,7 @@ public class ExecutorsTest extends JSR16 /** * invoke of a collable runs it to completion */ - public void testInvokeCallable () { + public void testInvokeCallable() { try { Executor e = new DirectExecutor(); String result = Executors.invoke(e, new StringTask()); @@ -281,10 +265,10 @@ public class ExecutorsTest extends JSR16 /** * execute with null executor throws NPE */ - public void testNullExecuteRunnable () { + public void testNullExecuteRunnable() { try { - MyTask task = new MyTask(); - assertFalse(task.isCompleted()); + TrackedShortRunnable task = new TrackedShortRunnable(); + assertFalse(task.done); Future future = Executors.execute(null, task, TEST_STRING); shouldThrow(); } @@ -301,7 +285,7 @@ public class ExecutorsTest extends JSR16 public void testExecuteNullRunnable() { try { Executor e = new DirectExecutor(); - MyTask task = null; + TrackedShortRunnable task = null; Future future = Executors.execute(e, task, TEST_STRING); shouldThrow(); } @@ -315,10 +299,10 @@ public class ExecutorsTest extends JSR16 /** * invoke of a null runnable throws NPE */ - public void testInvokeNullRunnable () { + public void testInvokeNullRunnable() { try { Executor e = new DirectExecutor(); - MyTask task = null; + TrackedShortRunnable task = null; Executors.invoke(e, task); shouldThrow(); } @@ -332,7 +316,7 @@ public class ExecutorsTest extends JSR16 /** * execute of a null callable throws NPE */ - public void testExecuteNullCallable () { + public void testExecuteNullCallable() { try { Executor e = new DirectExecutor(); StringTask t = null; @@ -349,7 +333,7 @@ public class ExecutorsTest extends JSR16 /** * invoke of a null callable throws NPE */ - public void testInvokeNullCallable () { + public void testInvokeNullCallable() { try { Executor e = new DirectExecutor(); StringTask t = null;