TransformExecutorServices { public static TransformExecutorService parallel(ExecutorService executor) { return new ParallelTransformExecutor(executor); } private  TransformExecutorServices(); static TransformExecutorService parallel(ExecutorService executor); static TransformExecutorService serial(ExecutorService executor);  }
@Test public void parallelScheduleMultipleSchedulesBothImmediately() { @SuppressWarnings("unchecked") DirectTransformExecutor<Object> first = mock(DirectTransformExecutor.class); @SuppressWarnings("unchecked") DirectTransformExecutor<Object> second = mock(DirectTransformExecutor.class); TransformExecutorService parallel = TransformExecutorServices.parallel(executorService); parallel.schedule(first); parallel.schedule(second); verify(first).run(); verify(second).run(); parallel.complete(first); parallel.complete(second); }
@Test public void parallelRejectedStillActiveThrows() { @SuppressWarnings("unchecked") DirectTransformExecutor<Object> first = mock(DirectTransformExecutor.class); TransformExecutorService parallel = TransformExecutorServices.parallel(executorService); executorService.shutdown(); thrown.expect(IllegalStateException.class); thrown.expectMessage("still active"); parallel.schedule(first); }
@Test public void parallelRejectedShutdownSucceeds() { @SuppressWarnings("unchecked") DirectTransformExecutor<Object> first = mock(DirectTransformExecutor.class); TransformExecutorService parallel = TransformExecutorServices.parallel(executorService); executorService.shutdown(); parallel.shutdown(); parallel.schedule(first); }