CompletableFutureTask extends CompletableFuture<R> implements Runnable { public CompletableFutureTask<R> runAsync(Executor executor) { executor.execute(this); return this; } CompletableFutureTask(Callable<R> task); @Override void run(); CompletableFutureTask<R> runAsync(Executor executor); static CompletableFutureTask<T> runAsync(Callable<T> task, Executor executor); @Override boolean cancel(boolean mayInterruptIfRunning);  }
@Test public void whenSupplyObjectThenReturnIt() throws Exception { Object res = new Object(); CompletableFutureTask<Object> task = CompletableFutureTask.runAsync(() -> res, executor); assertSame(res, task.get()); }
@Test public void whenTaskThrowsThenThrowExecutionException() throws InterruptedException { CompletableFutureTask<Integer> task = CompletableFutureTask.runAsync(() -> { throw new MyException(); }, executor); try { task.get(); fail(); } catch (ExecutionException exc) { assertTrue(exc.getCause() instanceof MyException); } }