@GwtIncompatible // get() timeout public void testTransformAsync_asyncFunction_timeout() throws InterruptedException, ExecutionException { AsyncFunction<String, Integer> function = constantAsyncFunction(immediateFuture(1)); ListenableFuture<Integer> future = transformAsync(SettableFuture.<String>create(), function, directExecutor()); try { future.get(1, MILLISECONDS); fail(); } catch (TimeoutException expected) { } }
public void testTransformAsync_genericsWildcard_AsyncFunction() throws Exception { ListenableFuture<?> nullFuture = immediateFuture(null); ListenableFuture<?> chainedFuture = transformAsync(nullFuture, constantAsyncFunction(nullFuture), directExecutor()); assertNull(getDone(chainedFuture)); }
public void testCatchingAsync_rejectionPropagatesToOutput() throws Exception { SettableFuture<String> input = SettableFuture.create(); ListenableFuture<String> transformed = catchingAsync( input, Throwable.class, constantAsyncFunction(immediateFuture("foo")), REJECTING_EXECUTOR); input.setException(new Exception()); try { getDone(transformed); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } }
public void testTransformAsync_asyncFunction_nullInsteadOfFuture() throws Exception { ListenableFuture<?> inputFuture = immediateFuture("a"); ListenableFuture<?> chainedFuture = transformAsync(inputFuture, constantAsyncFunction(null), directExecutor()); try { getDone(chainedFuture); fail(); } catch (ExecutionException expected) { NullPointerException cause = (NullPointerException) expected.getCause(); assertThat(cause) .hasMessageThat() .contains( "AsyncFunction.apply returned null instead of a Future. " + "Did you mean to return immediateFuture(null)?"); } }
@GwtIncompatible // get() timeout public void testTransformAsync_asyncFunction_timeout() throws InterruptedException, ExecutionException { AsyncFunction<String, Integer> function = constantAsyncFunction(immediateFuture(1)); ListenableFuture<Integer> future = transformAsync(SettableFuture.<String>create(), function, directExecutor()); try { future.get(1, MILLISECONDS); fail(); } catch (TimeoutException expected) { } }
public void testTransformAsync_asyncFunction_nullInsteadOfFuture() throws Exception { ListenableFuture<?> inputFuture = immediateFuture("a"); ListenableFuture<?> chainedFuture = transformAsync(inputFuture, constantAsyncFunction(null), directExecutor()); try { getDone(chainedFuture); fail(); } catch (ExecutionException expected) { NullPointerException cause = (NullPointerException) expected.getCause(); assertThat(cause).hasMessage("AsyncFunction.apply returned null instead of a Future. " + "Did you mean to return immediateFuture(null)?"); } }
public void testTransformAsync_genericsWildcard_AsyncFunction() throws Exception { ListenableFuture<?> nullFuture = immediateFuture(null); ListenableFuture<?> chainedFuture = transformAsync(nullFuture, constantAsyncFunction(nullFuture), directExecutor()); assertNull(getDone(chainedFuture)); }
public void testCatchingAsync_rejectionPropagatesToOutput() throws Exception { SettableFuture<String> input = SettableFuture.create(); ListenableFuture<String> transformed = catchingAsync( input, Throwable.class, constantAsyncFunction(immediateFuture("foo")), REJECTING_EXECUTOR); input.setException(new Exception()); try { getDone(transformed); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } }