ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CompletableFutureTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.185 by jsr166, Mon May 29 19:15:02 2017 UTC vs.
Revision 1.195 by jsr166, Sun Jul 22 20:09:31 2018 UTC

# Line 41 | Line 41 | import java.util.function.Function;
41   import java.util.function.Predicate;
42   import java.util.function.Supplier;
43  
44 import junit.framework.AssertionFailedError;
44   import junit.framework.Test;
45   import junit.framework.TestSuite;
46  
# Line 59 | Line 58 | public class CompletableFutureTest exten
58      void checkIncomplete(CompletableFuture<?> f) {
59          assertFalse(f.isDone());
60          assertFalse(f.isCancelled());
61 <        assertTrue(f.toString().contains("Not completed"));
61 >        assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
62 >
63 >        Object result = null;
64          try {
65 <            assertNull(f.getNow(null));
65 >            result = f.getNow(null);
66          } catch (Throwable fail) { threadUnexpectedException(fail); }
67 +        assertNull(result);
68 +
69          try {
70              f.get(randomExpiredTimeout(), randomTimeUnit());
71              shouldThrow();
# Line 82 | Line 85 | public class CompletableFutureTest exten
85          assertTrue(f.isDone());
86          assertFalse(f.isCancelled());
87          assertFalse(f.isCompletedExceptionally());
88 <        assertTrue(f.toString().contains("[Completed normally]"));
88 >        assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
89      }
90  
91      /**
# Line 138 | Line 141 | public class CompletableFutureTest exten
141          assertFalse(f.isCancelled());
142          assertTrue(f.isDone());
143          assertTrue(f.isCompletedExceptionally());
144 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
144 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
145      }
146  
147      void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
# Line 193 | Line 196 | public class CompletableFutureTest exten
196          assertTrue(f.isDone());
197          assertTrue(f.isCompletedExceptionally());
198          assertTrue(f.isCancelled());
199 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
199 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
200      }
201  
202      /**
# Line 292 | Line 295 | public class CompletableFutureTest exten
295          }
296  
297          f = new CompletableFuture<>();
298 <        f.completeExceptionally(ex = new CFException());
298 >        f.completeExceptionally(new CFException());
299          f.obtrudeValue(v1);
300          checkCompletedNormally(f, v1);
301          f.obtrudeException(ex = new CFException());
# Line 329 | Line 332 | public class CompletableFutureTest exten
332      /**
333       * toString indicates current completion state
334       */
335 <    public void testToString() {
336 <        CompletableFuture<String> f;
337 <
338 <        f = new CompletableFuture<String>();
339 <        assertTrue(f.toString().contains("[Not completed]"));
335 >    public void testToString_incomplete() {
336 >        CompletableFuture<String> f = new CompletableFuture<>();
337 >        assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
338 >        if (testImplementationDetails)
339 >            assertEquals(identityString(f) + "[Not completed]",
340 >                         f.toString());
341 >    }
342  
343 +    public void testToString_normal() {
344 +        CompletableFuture<String> f = new CompletableFuture<>();
345          assertTrue(f.complete("foo"));
346 <        assertTrue(f.toString().contains("[Completed normally]"));
346 >        assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
347 >        if (testImplementationDetails)
348 >            assertEquals(identityString(f) + "[Completed normally]",
349 >                         f.toString());
350 >    }
351  
352 <        f = new CompletableFuture<String>();
352 >    public void testToString_exception() {
353 >        CompletableFuture<String> f = new CompletableFuture<>();
354          assertTrue(f.completeExceptionally(new IndexOutOfBoundsException()));
355 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
355 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
356 >        if (testImplementationDetails)
357 >            assertTrue(f.toString().startsWith(
358 >                               identityString(f) + "[Completed exceptionally: "));
359 >    }
360  
361 +    public void testToString_cancelled() {
362          for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
363 <            f = new CompletableFuture<String>();
363 >            CompletableFuture<String> f = new CompletableFuture<>();
364              assertTrue(f.cancel(mayInterruptIfRunning));
365 <            assertTrue(f.toString().contains("[Completed exceptionally]"));
365 >            assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
366 >            if (testImplementationDetails)
367 >                assertTrue(f.toString().startsWith(
368 >                                   identityString(f) + "[Completed exceptionally: "));
369          }
370      }
371  
# Line 1238 | Line 1258 | public class CompletableFutureTest exten
1258          r.assertInvoked();
1259      }}
1260  
1261 +    @SuppressWarnings("FutureReturnValueIgnored")
1262      public void testRunAsync_rejectingExecutor() {
1263          CountingRejectingExecutor e = new CountingRejectingExecutor();
1264          try {
# Line 1284 | Line 1305 | public class CompletableFutureTest exten
1305          r.assertInvoked();
1306      }}
1307  
1308 +    @SuppressWarnings("FutureReturnValueIgnored")
1309      public void testSupplyAsync_rejectingExecutor() {
1310          CountingRejectingExecutor e = new CountingRejectingExecutor();
1311          try {
# Line 3234 | Line 3256 | public class CompletableFutureTest exten
3256      /**
3257       * Completion methods throw NullPointerException with null arguments
3258       */
3259 +    @SuppressWarnings("FutureReturnValueIgnored")
3260      public void testNPE() {
3261          CompletableFuture<Integer> f = new CompletableFuture<>();
3262          CompletableFuture<Integer> g = new CompletableFuture<>();
# Line 4170 | Line 4193 | public class CompletableFutureTest exten
4193          static void assertZero(CompletableFuture<?> f) {
4194              try {
4195                  f.getNow(null);
4196 <                throw new AssertionFailedError("should throw");
4196 >                throw new AssertionError("should throw");
4197              } catch (CompletionException success) {
4198                  assertTrue(success.getCause() instanceof ZeroException);
4199              }
# Line 4295 | Line 4318 | public class CompletableFutureTest exten
4318      }
4319  
4320      /** Test long recursive chains of CompletableFutures with cascading completions */
4321 +    @SuppressWarnings("FutureReturnValueIgnored")
4322      public void testRecursiveChains() throws Throwable {
4323          for (ExecutionMode m : ExecutionMode.values())
4324          for (boolean addDeadEnds : new boolean[] { true, false })
# Line 4319 | Line 4343 | public class CompletableFutureTest exten
4343       * A single CompletableFuture with many dependents.
4344       * A demo of scalability - runtime is O(n).
4345       */
4346 +    @SuppressWarnings("FutureReturnValueIgnored")
4347      public void testManyDependents() throws Throwable {
4348          final int n = expensiveTests ? 1_000_000 : 10;
4349          final CompletableFuture<Void> head = new CompletableFuture<>();
# Line 4348 | Line 4373 | public class CompletableFutureTest exten
4373      }
4374  
4375      /** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */
4376 +    @SuppressWarnings("FutureReturnValueIgnored")
4377      public void testCoCompletionGarbageRetention() throws Throwable {
4378          final int n = expensiveTests ? 1_000_000 : 10;
4379          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
# Line 4366 | Line 4392 | public class CompletableFutureTest exten
4392              f.complete(null);
4393  
4394              f = new CompletableFuture<>();
4395 <            CompletableFuture.anyOf(new CompletableFuture<?>[] { f, incomplete });
4395 >            CompletableFuture.anyOf(f, incomplete);
4396              f.complete(null);
4397          }
4398  
# Line 4384 | Line 4410 | public class CompletableFutureTest exten
4410              f.complete(null);
4411  
4412              f = new CompletableFuture<>();
4413 <            CompletableFuture.anyOf(new CompletableFuture<?>[] { incomplete, f });
4413 >            CompletableFuture.anyOf(incomplete, f);
4414              f.complete(null);
4415          }
4416      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines