Async { public static <T> CompletableFuture<T> run(Callable<T> callable, ExecutorService executor) { ExecutorService executorService = ofNullable(executor).orElse(DEFAULT_EXECUTOR); CompletableFuture<T> result = new CompletableFuture<>(); CompletableFuture.runAsync(() -> { try { result.complete(callable.call()); } catch (Throwable e) { result.completeExceptionally(e); } }, executorService); return result; }  static CompletableFuture<T> run(Callable<T> callable, ExecutorService executor); static CompletableFuture<T> run(Callable<T> callable); static ExecutorService getDefaultExecutor(); static ScheduledExecutorService defaultExecutorService();  }
@Test public void testRunSuccessful() throws Exception { assertThat( Async.run(() -> "anything").get(), is("anything") ); }
@Test(expected = ExecutionException.class) public void testRunWithException() throws Exception { Async.run(() -> { throw new RuntimeException("Exception"); }).get(); }