/** * Constructs a {@link ListenableFuture} that has failed with the given failure. Thus the * resulting future can not block, or be canceled. Calls to {@link ListenableFuture#get()} will * immediately throw an {@link ExecutionException}. * * @since 1.2.0 * @param <T> The result object type returned by the returned future * @param failure to provide as cause for ExecutionException thrown from .get() call * @return Already satisfied future */ public static <T> ListenableFuture<T> immediateFailureFuture(Throwable failure) { return new ImmediateFailureListenableFuture<>(failure); }
/** * Constructs a {@link ListenableFuture} that has failed with the given failure. Thus the * resulting future can not block, or be canceled. Calls to {@link ListenableFuture#get()} will * immediately throw an {@link ExecutionException}. * * @since 1.2.0 * @param <T> The result object type returned by the returned future * @param failure to provide as cause for ExecutionException thrown from .get() call * @return Already satisfied future */ public static <T> ListenableFuture<T> immediateFailureFuture(Throwable failure) { return new ImmediateFailureListenableFuture<>(failure); }
@Test public void getTest() { Exception failure = new Exception(); ListenableFuture<?> testFuture = new ImmediateFailureListenableFuture<>(failure); ImmediateListenableFutureTest.failureTest(testFuture, failure); }
@Test public void addCallbackTest() { Throwable failure = new Exception(); ListenableFuture<?> testFuture = new ImmediateFailureListenableFuture<>(failure); ImmediateListenableFutureTest.failureAddCallbackTest(testFuture, failure); }
@Test public void cancelTest() { ListenableFuture<?> testFuture = new ImmediateFailureListenableFuture<>(null); ImmediateListenableFutureTest.cancelTest(testFuture); }
@Test public void addListenerTest() { ListenableFuture<?> testFuture = new ImmediateFailureListenableFuture<>(null); ImmediateListenableFutureTest.addListenerTest(testFuture); }
@Test public void getRunningStackTraceTest() { ListenableFuture<?> testFuture = new ImmediateFailureListenableFuture<>(null); ImmediateListenableFutureTest.getRunningStackTraceTest(testFuture); } }
@Test public void addAsCallbackFailureTest() throws InterruptedException { Exception e = new Exception(); ListenableFuture<String> failureFuture = new ImmediateFailureListenableFuture<>(e); failureFuture.addCallback(slf); assertTrue(slf.isDone()); try { slf.get(); fail("Exception should have thrown"); } catch (ExecutionException ee) { assertTrue(ee.getCause() == e); } }