Producers { public static <T> ListenableFuture<Set<T>> createFutureSingletonSet(ListenableFuture<T> future) { return Futures.transform(future, new Function<T, Set<T>>() { @Override public Set<T> apply(T value) { return ImmutableSet.of(value); } }); } private  Producers(); static ListenableFuture<Produced<T>> createFutureProduced(ListenableFuture<T> future); static ListenableFuture<Set<T>> createFutureSingletonSet(ListenableFuture<T> future); static ListenableFuture<T> submitToExecutor(Callable<T> callable, Executor executor); static Producer<T> producerFromProvider(final Provider<T> provider);  }
@Test public void createFutureSingletonSet_success() throws Exception { ListenableFuture<String> future = Futures.immediateFuture("monkey"); ListenableFuture<Set<String>> setFuture = Producers.createFutureSingletonSet(future); assertThat(setFuture.isDone()).isTrue(); assertThat(setFuture.get()).containsExactly("monkey"); }
@Test public void createFutureSingletonSet_failure() throws Exception { ListenableFuture<String> future = Futures.immediateFailedFuture(new RuntimeException("monkey")); ListenableFuture<Set<String>> setFuture = Producers.createFutureSingletonSet(future); assertThat(setFuture.isDone()).isTrue(); try { setFuture.get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause()).hasMessage("monkey"); } }