NotifyingFutureTask extends FutureTask<Void> { public static NotifyingFutureTask completed() { NotifyingFutureTask f = new NotifyingFutureTask(NOP); f.run(); return f; } NotifyingFutureTask(Callable<Void> callable);  NotifyingFutureTask(Runnable task); void onComplete(Runnable onComplete); static NotifyingFutureTask completed();  }
@Test public void completed() throws Exception{ CountingRunnable runnable = new CountingRunnable(); NotifyingFutureTask nft = NotifyingFutureTask.completed(); nft.onComplete(runnable); assertEquals("Callback should still be invoked if already done", 1, runnable.count); }