ListenableFutureTask extends FutureTask<V> implements ListenableFuture<V> { public static <V> ListenableFutureTask<V> create(Callable<V> callable) { return new ListenableFutureTask<V>(callable); } ListenableFutureTask(Callable<V> callable);   ListenableFutureTask(Runnable runnable, V result); static ListenableFutureTask<V> create(Callable<V> callable); static ListenableFutureTask<V> create(
            Runnable runnable, V result); @Override void addListener(Runnable listener, Executor exec); @Override void addListener(Runnable listener);  }
@Test public void testCreate() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); ListenableFutureTask<Boolean> futureTask = ListenableFutureTask.create(new Callable<Boolean>() { @Override public Boolean call() throws Exception { countDownLatch.countDown(); return true; } }); futureTask.run(); countDownLatch.await(); }
@Test public void testRunnableResponse() throws ExecutionException, InterruptedException { ListenableFutureTask<Boolean> futureTask = ListenableFutureTask.create(new Runnable() { @Override public void run() { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } }, true); futureTask.run(); Boolean result = futureTask.get(); assertThat(result, is(true)); }