### Question:
CompletableFutureUtils { public static <T, U> CompletionStage<U> flatMap(final CompletionStage<T> future, final Function<? super T, CompletionStage<U>> f) { return future.thenComposeAsync(f); } private  CompletableFutureUtils(); static CompletableFuture<T> successful(final T object); static CompletableFuture<T> exceptionallyCompletedFuture(final Throwable e); static CompletableFuture<T> failed(final Throwable e); static void transferResult(final CompletionStage<T> source,
                                          final CompletableFuture<T> target); static CompletionStage<T> onFailure(final CompletionStage<T> future, final Consumer<? super Throwable> consumer); static CompletionStage<T> onSuccess(final CompletionStage<T> future, final Consumer<? super T> consumer); static CompletionStage<T> recover(final CompletionStage<T> future, final Function<Throwable, ? extends T> f); static CompletableFuture<T> recoverWith(final CompletionStage<T> future, final Function<? super Throwable, CompletionStage<T>> f); static CompletableFuture<T> recoverWith(final CompletionStage<T> future, final Function<? super Throwable, CompletionStage<T>> f, final Executor executor); static T orElseThrow(final CompletionStage<T> stage, Supplier<? extends X> exceptionSupplier); static T orElseGet(final CompletionStage<T> stage, final Supplier<T> other); static CompletionStage<U> map(final CompletionStage<T> future, final Function<? super T,? extends U> f); static CompletionStage<U> flatMap(final CompletionStage<T> future, final Function<? super T, CompletionStage<U>> f); static CompletableFuture<List<T>> listOfFuturesToFutureOfList(final List<? extends CompletionStage<T>> list); static CompletableFuture<List<T>> sequence(final List<? extends CompletionStage<T>> list);  }### Answer:
@Test public void testFlatMap() throws Exception { final CompletionStage<String> future = successful("hello"); final Function<String, CompletionStage<Integer>> f = s -> successful(s.length()); final CompletionStage<Integer> result = flatMap(future, f); assertThat(result.toCompletableFuture().join()).isEqualTo(5); }