--- jsr166/src/test/tck/CompletableFutureTest.java 2017/08/16 17:18:34 1.188 +++ jsr166/src/test/tck/CompletableFutureTest.java 2018/07/22 20:17:46 1.196 @@ -41,7 +41,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; -import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestSuite; @@ -60,9 +59,13 @@ public class CompletableFutureTest exten assertFalse(f.isDone()); assertFalse(f.isCancelled()); assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]")); + + Object result = null; try { - assertNull(f.getNow(null)); + result = f.getNow(null); } catch (Throwable fail) { threadUnexpectedException(fail); } + assertNull(result); + try { f.get(randomExpiredTimeout(), randomTimeUnit()); shouldThrow(); @@ -74,11 +77,15 @@ public class CompletableFutureTest exten void checkCompletedNormally(CompletableFuture f, T value) { checkTimedGet(f, value); + assertEquals(value, f.join()); + assertEquals(value, f.getNow(null)); + + T result = null; try { - assertEquals(value, f.join()); - assertEquals(value, f.getNow(null)); - assertEquals(value, f.get()); + result = f.get(); } catch (Throwable fail) { threadUnexpectedException(fail); } + assertEquals(value, result); + assertTrue(f.isDone()); assertFalse(f.isCancelled()); assertFalse(f.isCompletedExceptionally()); @@ -292,7 +299,7 @@ public class CompletableFutureTest exten } f = new CompletableFuture<>(); - f.completeExceptionally(ex = new CFException()); + f.completeExceptionally(new CFException()); f.obtrudeValue(v1); checkCompletedNormally(f, v1); f.obtrudeException(ex = new CFException()); @@ -330,7 +337,7 @@ public class CompletableFutureTest exten * toString indicates current completion state */ public void testToString_incomplete() { - CompletableFuture f = new CompletableFuture(); + CompletableFuture f = new CompletableFuture<>(); assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]")); if (testImplementationDetails) assertEquals(identityString(f) + "[Not completed]", @@ -338,7 +345,7 @@ public class CompletableFutureTest exten } public void testToString_normal() { - CompletableFuture f = new CompletableFuture(); + CompletableFuture f = new CompletableFuture<>(); assertTrue(f.complete("foo")); assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]")); if (testImplementationDetails) @@ -347,7 +354,7 @@ public class CompletableFutureTest exten } public void testToString_exception() { - CompletableFuture f = new CompletableFuture(); + CompletableFuture f = new CompletableFuture<>(); assertTrue(f.completeExceptionally(new IndexOutOfBoundsException())); assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); if (testImplementationDetails) @@ -357,7 +364,7 @@ public class CompletableFutureTest exten public void testToString_cancelled() { for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { - CompletableFuture f = new CompletableFuture(); + CompletableFuture f = new CompletableFuture<>(); assertTrue(f.cancel(mayInterruptIfRunning)); assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); if (testImplementationDetails) @@ -4190,7 +4197,7 @@ public class CompletableFutureTest exten static void assertZero(CompletableFuture f) { try { f.getNow(null); - throw new AssertionFailedError("should throw"); + throw new AssertionError("should throw"); } catch (CompletionException success) { assertTrue(success.getCause() instanceof ZeroException); } @@ -4389,7 +4396,7 @@ public class CompletableFutureTest exten f.complete(null); f = new CompletableFuture<>(); - CompletableFuture.anyOf(new CompletableFuture[] { f, incomplete }); + CompletableFuture.anyOf(f, incomplete); f.complete(null); } @@ -4407,7 +4414,7 @@ public class CompletableFutureTest exten f.complete(null); f = new CompletableFuture<>(); - CompletableFuture.anyOf(new CompletableFuture[] { incomplete, f }); + CompletableFuture.anyOf(incomplete, f); f.complete(null); } }