diff options
Diffstat (limited to 'android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureCancellationCauseTest.java')
-rw-r--r-- | android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureCancellationCauseTest.java | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureCancellationCauseTest.java b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureCancellationCauseTest.java index 9aee78029..d00f95f31 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureCancellationCauseTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureCancellationCauseTest.java @@ -17,6 +17,7 @@ package com.google.common.util.concurrent; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertThrows; import java.lang.reflect.Method; import java.net.URLClassLoader; @@ -89,12 +90,8 @@ public class AbstractFutureCancellationCauseTest extends TestCase { assertTrue(future.isCancelled()); assertTrue(future.isDone()); assertNull(tryInternalFastPathGetFailure(future)); - try { - future.get(); - fail("Expected CancellationException"); - } catch (CancellationException e) { - assertNotNull(e.getCause()); - } + CancellationException e = assertThrows(CancellationException.class, () -> future.get()); + assertNotNull(e.getCause()); } public void testCancel_notDoneInterrupt() throws Exception { @@ -103,12 +100,8 @@ public class AbstractFutureCancellationCauseTest extends TestCase { assertTrue(future.isCancelled()); assertTrue(future.isDone()); assertNull(tryInternalFastPathGetFailure(future)); - try { - future.get(); - fail("Expected CancellationException"); - } catch (CancellationException e) { - assertNotNull(e.getCause()); - } + CancellationException e = assertThrows(CancellationException.class, () -> future.get()); + assertNotNull(e.getCause()); } public void testSetFuture_misbehavingFutureDoesNotThrow() throws Exception { @@ -151,13 +144,9 @@ public class AbstractFutureCancellationCauseTest extends TestCase { "setFuture", future.getClass().getClassLoader().loadClass(ListenableFuture.class.getName())) .invoke(future, badFuture); - try { - future.get(); - fail(); - } catch (CancellationException expected) { - assertThat(expected).hasCauseThat().isInstanceOf(IllegalArgumentException.class); - assertThat(expected).hasCauseThat().hasMessageThat().contains(badFuture.toString()); - } + CancellationException expected = assertThrows(CancellationException.class, () -> future.get()); + assertThat(expected).hasCauseThat().isInstanceOf(IllegalArgumentException.class); + assertThat(expected).hasCauseThat().hasMessageThat().contains(badFuture.toString()); } private Future<?> newFutureInstance() throws Exception { |