aboutsummaryrefslogtreecommitdiff
path: root/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java')
-rw-r--r--guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java49
1 files changed, 9 insertions, 40 deletions
diff --git a/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java b/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java
index 24990200d..e0d579249 100644
--- a/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java
+++ b/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.util.concurrent.Futures.transformAsync;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly;
+import static org.junit.Assert.assertThrows;
import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture;
import java.util.concurrent.CancellationException;
@@ -82,23 +83,13 @@ public class FuturesTransformAsyncTest extends AbstractChainedListenableFutureTe
public void testFutureGetThrowsCancellationIfInputCancelled() throws Exception {
inputFuture.cancel(true); // argument is ignored
- try {
- resultFuture.get();
- fail("Result future must throw CancellationException" + " if input future is cancelled.");
- } catch (CancellationException expected) {
- }
+ assertThrows(CancellationException.class, () -> resultFuture.get());
}
public void testFutureGetThrowsCancellationIfOutputCancelled() throws Exception {
inputFuture.set(SLOW_OUTPUT_VALID_INPUT_DATA);
outputFuture.cancel(true); // argument is ignored
- try {
- resultFuture.get();
- fail(
- "Result future must throw CancellationException"
- + " if function output future is cancelled.");
- } catch (CancellationException expected) {
- }
+ assertThrows(CancellationException.class, () -> resultFuture.get());
}
public void testAsyncToString() throws Exception {
@@ -111,11 +102,7 @@ public class FuturesTransformAsyncTest extends AbstractChainedListenableFutureTe
assertTrue(resultFuture.isCancelled());
assertTrue(inputFuture.isCancelled());
assertFalse(outputFuture.isCancelled());
- try {
- resultFuture.get();
- fail("Result future is cancelled and should have thrown a" + " CancellationException");
- } catch (CancellationException expected) {
- }
+ assertThrows(CancellationException.class, () -> resultFuture.get());
}
public void testFutureCancellableBeforeOutputCompletion() throws Exception {
@@ -124,11 +111,7 @@ public class FuturesTransformAsyncTest extends AbstractChainedListenableFutureTe
assertTrue(resultFuture.isCancelled());
assertFalse(inputFuture.isCancelled());
assertTrue(outputFuture.isCancelled());
- try {
- resultFuture.get();
- fail("Result future is cancelled and should have thrown a" + " CancellationException");
- } catch (CancellationException expected) {
- }
+ assertThrows(CancellationException.class, () -> resultFuture.get());
}
public void testFutureCancellableBeforeFunctionCompletion() throws Exception {
@@ -146,20 +129,10 @@ public class FuturesTransformAsyncTest extends AbstractChainedListenableFutureTe
assertTrue(resultFuture.isCancelled());
assertFalse(inputFuture.isCancelled());
assertFalse(outputFuture.isCancelled());
- try {
- resultFuture.get();
- fail("Result future is cancelled and should have thrown a" + " CancellationException");
- } catch (CancellationException expected) {
- }
+ assertThrows(CancellationException.class, () -> resultFuture.get());
funcCompletionLatch.countDown(); // allow the function to complete
- try {
- outputFuture.get();
- fail(
- "The function output future is cancelled and should have thrown a"
- + " CancellationException");
- } catch (CancellationException expected) {
- }
+ assertThrows(CancellationException.class, () -> outputFuture.get());
}
public void testFutureCancelAfterCompletion() throws Exception {
@@ -174,12 +147,8 @@ public class FuturesTransformAsyncTest extends AbstractChainedListenableFutureTe
public void testFutureGetThrowsRuntimeException() throws Exception {
BadFuture badInput = new BadFuture(Futures.immediateFuture(20));
ListenableFuture<String> chain = buildChainingFuture(badInput);
- try {
- chain.get();
- fail("Future.get must throw an exception when the input future fails.");
- } catch (ExecutionException e) {
- assertSame(RuntimeException.class, e.getCause().getClass());
- }
+ ExecutionException e = assertThrows(ExecutionException.class, () -> chain.get());
+ assertSame(RuntimeException.class, e.getCause().getClass());
}
/** Proxy to throw a {@link RuntimeException} out of the {@link #get()} method. */