TransformExecutorServices { public static TransformExecutorService serial(ExecutorService executor) { return new SerialTransformExecutor(executor); } private  TransformExecutorServices(); static TransformExecutorService parallel(ExecutorService executor); static TransformExecutorService serial(ExecutorService executor);  }
@Test public void serialScheduleTwoWaitsForFirstToComplete() { @SuppressWarnings("unchecked") DirectTransformExecutor<Object> first = mock(DirectTransformExecutor.class); @SuppressWarnings("unchecked") DirectTransformExecutor<Object> second = mock(DirectTransformExecutor.class); TransformExecutorService serial = TransformExecutorServices.serial(executorService); serial.schedule(first); verify(first).run(); serial.schedule(second); verify(second, never()).run(); serial.complete(first); verify(second).run(); serial.complete(second); }
@Test public void serialCompleteNotExecutingTaskThrows() { @SuppressWarnings("unchecked") DirectTransformExecutor<Object> first = mock(DirectTransformExecutor.class); @SuppressWarnings("unchecked") DirectTransformExecutor<Object> second = mock(DirectTransformExecutor.class); TransformExecutorService serial = TransformExecutorServices.serial(executorService); serial.schedule(first); thrown.expect(IllegalStateException.class); thrown.expectMessage("unexpected currently executing"); serial.complete(second); }
@Test public void serialShutdownCompleteActive() { @SuppressWarnings("unchecked") DirectTransformExecutor<Object> first = mock(DirectTransformExecutor.class); @SuppressWarnings("unchecked") DirectTransformExecutor<Object> second = mock(DirectTransformExecutor.class); TransformExecutorService serial = TransformExecutorServices.serial(executorService); serial.schedule(first); verify(first).run(); serial.schedule(second); verify(second, never()).run(); serial.shutdown(); serial.complete(first); verify(second, never()).run(); }