@Test public void testCheckSuccess() { checkSuccess(immediateFuture("Alice"), "this should not fail"); assertFailure( () -> checkSuccess(immediateFailedFuture(new IllegalStateException("some failure")), "msg"), expect( IllegalArgumentException.class, "msg", expect(IllegalStateException.class, "some failure"))); assertFailure( () -> checkSuccess(immediateFailedFuture(new IOException("some failure")), "msg"), expect( IllegalArgumentException.class, "msg", expect( RuntimeException.class, "java.io.IOException: some failure", expect(IOException.class, "some failure")))); assertFailure(() -> checkSuccess(SettableFuture.create(), "msg"), expect(IllegalArgumentException.class, "future not done yet")); assertFailure(() -> checkSuccess(null, "msg"), expect(NullPointerException.class, "future is null")); }
public static void checkSuccess(Future<?> future, String errorMessage) { requireNonNull(future, "future is null"); requireNonNull(errorMessage, "errorMessage is null"); checkArgument(future.isDone(), "future not done yet"); try { getFutureValue(future); } catch (RuntimeException e) { throw new IllegalArgumentException(errorMessage, e); } }
MoreFutures { public static void checkSuccess(Future<?> future, String errorMessage) { requireNonNull(future, "future is null"); requireNonNull(errorMessage, "errorMessage is null"); checkArgument(future.isDone(), "future not done yet"); try { getFutureValue(future); } catch (RuntimeException e) { throw new IllegalArgumentException(errorMessage, e); } } }
MoreFutures { public static void checkSuccess(Future<?> future, String errorMessage) { requireNonNull(future, "future is null"); requireNonNull(errorMessage, "errorMessage is null"); checkArgument(future.isDone(), "future not done yet"); try { getFutureValue(future); } catch (RuntimeException e) { throw new IllegalArgumentException(errorMessage, e); } } private  MoreFutures(); }
MoreFutures { public static void checkSuccess(Future<?> future, String errorMessage) { requireNonNull(future, "future is null"); requireNonNull(errorMessage, "errorMessage is null"); checkArgument(future.isDone(), "future not done yet"); try { getFutureValue(future); } catch (RuntimeException e) { throw new IllegalArgumentException(errorMessage, e); } } private  MoreFutures(); static void propagateCancellation(ListenableFuture<? extends X> source, Future<? extends Y> destination, boolean mayInterruptIfRunning); static void mirror(ListenableFuture<? extends T> source, SettableFuture<? super T> destination, boolean mayInterruptIfRunning); static Throwable unwrapCompletionException(Throwable throwable); static CompletableFuture<V> unmodifiableFuture(CompletableFuture<V> future); static CompletableFuture<V> unmodifiableFuture(CompletableFuture<V> future, boolean propagateCancel); static CompletableFuture<V> failedFuture(Throwable throwable); static V getFutureValue(Future<V> future); static V getFutureValue(Future<V> future, Class<E> exceptionType); static Optional<T> tryGetFutureValue(Future<T> future); static Optional<V> tryGetFutureValue(Future<V> future, int timeout, TimeUnit timeUnit); static Optional<V> tryGetFutureValue(Future<V> future, int timeout, TimeUnit timeUnit, Class<E> exceptionType); static T getDone(Future<T> future); static void checkSuccess(Future<?> future, String errorMessage); static ListenableFuture<V> whenAnyComplete(Iterable<? extends ListenableFuture<? extends V>> futures); static ListenableFuture<V> whenAnyCompleteCancelOthers(Iterable<? extends ListenableFuture<? extends V>> futures); static CompletableFuture<V> firstCompletedFuture(Iterable<? extends CompletionStage<? extends V>> futures); static CompletableFuture<V> firstCompletedFuture(Iterable<? extends CompletionStage<? extends V>> futures, boolean propagateCancel); static CompletableFuture<List<V>> allAsList(List<CompletableFuture<? extends V>> futures); static ListenableFuture<T> addTimeout(ListenableFuture<T> future, Callable<T> onTimeout, Duration timeout, ScheduledExecutorService executorService); static CompletableFuture<T> addTimeout(CompletableFuture<T> future, Callable<T> onTimeout, Duration timeout, ScheduledExecutorService executorService); static CompletableFuture<V> toCompletableFuture(ListenableFuture<V> listenableFuture); static ListenableFuture<V> toListenableFuture(CompletableFuture<V> completableFuture); static void addSuccessCallback(ListenableFuture<T> future, Consumer<T> successCallback); static void addSuccessCallback(ListenableFuture<T> future, Runnable successCallback); static void addExceptionCallback(ListenableFuture<T> future, Consumer<Throwable> exceptionCallback); static void addExceptionCallback(ListenableFuture<T> future, Runnable exceptionCallback); }
MoreFutures { public static void checkSuccess(Future<?> future, String errorMessage) { requireNonNull(future, "future is null"); requireNonNull(errorMessage, "errorMessage is null"); checkArgument(future.isDone(), "future not done yet"); try { getFutureValue(future); } catch (RuntimeException e) { throw new IllegalArgumentException(errorMessage, e); } } private  MoreFutures(); static void propagateCancellation(ListenableFuture<? extends X> source, Future<? extends Y> destination, boolean mayInterruptIfRunning); static void mirror(ListenableFuture<? extends T> source, SettableFuture<? super T> destination, boolean mayInterruptIfRunning); static Throwable unwrapCompletionException(Throwable throwable); static CompletableFuture<V> unmodifiableFuture(CompletableFuture<V> future); static CompletableFuture<V> unmodifiableFuture(CompletableFuture<V> future, boolean propagateCancel); static CompletableFuture<V> failedFuture(Throwable throwable); static V getFutureValue(Future<V> future); static V getFutureValue(Future<V> future, Class<E> exceptionType); static Optional<T> tryGetFutureValue(Future<T> future); static Optional<V> tryGetFutureValue(Future<V> future, int timeout, TimeUnit timeUnit); static Optional<V> tryGetFutureValue(Future<V> future, int timeout, TimeUnit timeUnit, Class<E> exceptionType); static T getDone(Future<T> future); static void checkSuccess(Future<?> future, String errorMessage); static ListenableFuture<V> whenAnyComplete(Iterable<? extends ListenableFuture<? extends V>> futures); static ListenableFuture<V> whenAnyCompleteCancelOthers(Iterable<? extends ListenableFuture<? extends V>> futures); static CompletableFuture<V> firstCompletedFuture(Iterable<? extends CompletionStage<? extends V>> futures); static CompletableFuture<V> firstCompletedFuture(Iterable<? extends CompletionStage<? extends V>> futures, boolean propagateCancel); static CompletableFuture<List<V>> allAsList(List<CompletableFuture<? extends V>> futures); static ListenableFuture<T> addTimeout(ListenableFuture<T> future, Callable<T> onTimeout, Duration timeout, ScheduledExecutorService executorService); static CompletableFuture<T> addTimeout(CompletableFuture<T> future, Callable<T> onTimeout, Duration timeout, ScheduledExecutorService executorService); static CompletableFuture<V> toCompletableFuture(ListenableFuture<V> listenableFuture); static ListenableFuture<V> toListenableFuture(CompletableFuture<V> completableFuture); static void addSuccessCallback(ListenableFuture<T> future, Consumer<T> successCallback); static void addSuccessCallback(ListenableFuture<T> future, Runnable successCallback); static void addExceptionCallback(ListenableFuture<T> future, Consumer<Throwable> exceptionCallback); static void addExceptionCallback(ListenableFuture<T> future, Runnable exceptionCallback);  }