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.193 by jsr166, Tue Jan 30 04:07:09 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          try {
63              assertNull(f.getNow(null));
64          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 82 | Line 81 | public class CompletableFutureTest exten
81          assertTrue(f.isDone());
82          assertFalse(f.isCancelled());
83          assertFalse(f.isCompletedExceptionally());
84 <        assertTrue(f.toString().contains("[Completed normally]"));
84 >        assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
85      }
86  
87      /**
# Line 138 | Line 137 | public class CompletableFutureTest exten
137          assertFalse(f.isCancelled());
138          assertTrue(f.isDone());
139          assertTrue(f.isCompletedExceptionally());
140 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
140 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
141      }
142  
143      void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
# Line 193 | Line 192 | public class CompletableFutureTest exten
192          assertTrue(f.isDone());
193          assertTrue(f.isCompletedExceptionally());
194          assertTrue(f.isCancelled());
195 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
195 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
196      }
197  
198      /**
# Line 292 | Line 291 | public class CompletableFutureTest exten
291          }
292  
293          f = new CompletableFuture<>();
294 <        f.completeExceptionally(ex = new CFException());
294 >        f.completeExceptionally(new CFException());
295          f.obtrudeValue(v1);
296          checkCompletedNormally(f, v1);
297          f.obtrudeException(ex = new CFException());
# Line 329 | Line 328 | public class CompletableFutureTest exten
328      /**
329       * toString indicates current completion state
330       */
331 <    public void testToString() {
332 <        CompletableFuture<String> f;
333 <
334 <        f = new CompletableFuture<String>();
335 <        assertTrue(f.toString().contains("[Not completed]"));
331 >    public void testToString_incomplete() {
332 >        CompletableFuture<String> f = new CompletableFuture<>();
333 >        assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
334 >        if (testImplementationDetails)
335 >            assertEquals(identityString(f) + "[Not completed]",
336 >                         f.toString());
337 >    }
338  
339 +    public void testToString_normal() {
340 +        CompletableFuture<String> f = new CompletableFuture<>();
341          assertTrue(f.complete("foo"));
342 <        assertTrue(f.toString().contains("[Completed normally]"));
342 >        assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
343 >        if (testImplementationDetails)
344 >            assertEquals(identityString(f) + "[Completed normally]",
345 >                         f.toString());
346 >    }
347  
348 <        f = new CompletableFuture<String>();
348 >    public void testToString_exception() {
349 >        CompletableFuture<String> f = new CompletableFuture<>();
350          assertTrue(f.completeExceptionally(new IndexOutOfBoundsException()));
351 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
351 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
352 >        if (testImplementationDetails)
353 >            assertTrue(f.toString().startsWith(
354 >                               identityString(f) + "[Completed exceptionally: "));
355 >    }
356  
357 +    public void testToString_cancelled() {
358          for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
359 <            f = new CompletableFuture<String>();
359 >            CompletableFuture<String> f = new CompletableFuture<>();
360              assertTrue(f.cancel(mayInterruptIfRunning));
361 <            assertTrue(f.toString().contains("[Completed exceptionally]"));
361 >            assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
362 >            if (testImplementationDetails)
363 >                assertTrue(f.toString().startsWith(
364 >                                   identityString(f) + "[Completed exceptionally: "));
365          }
366      }
367  
# Line 1238 | Line 1254 | public class CompletableFutureTest exten
1254          r.assertInvoked();
1255      }}
1256  
1257 +    @SuppressWarnings("FutureReturnValueIgnored")
1258      public void testRunAsync_rejectingExecutor() {
1259          CountingRejectingExecutor e = new CountingRejectingExecutor();
1260          try {
# Line 1284 | Line 1301 | public class CompletableFutureTest exten
1301          r.assertInvoked();
1302      }}
1303  
1304 +    @SuppressWarnings("FutureReturnValueIgnored")
1305      public void testSupplyAsync_rejectingExecutor() {
1306          CountingRejectingExecutor e = new CountingRejectingExecutor();
1307          try {
# Line 3234 | Line 3252 | public class CompletableFutureTest exten
3252      /**
3253       * Completion methods throw NullPointerException with null arguments
3254       */
3255 +    @SuppressWarnings("FutureReturnValueIgnored")
3256      public void testNPE() {
3257          CompletableFuture<Integer> f = new CompletableFuture<>();
3258          CompletableFuture<Integer> g = new CompletableFuture<>();
# Line 4170 | Line 4189 | public class CompletableFutureTest exten
4189          static void assertZero(CompletableFuture<?> f) {
4190              try {
4191                  f.getNow(null);
4192 <                throw new AssertionFailedError("should throw");
4192 >                throw new AssertionError("should throw");
4193              } catch (CompletionException success) {
4194                  assertTrue(success.getCause() instanceof ZeroException);
4195              }
# Line 4295 | Line 4314 | public class CompletableFutureTest exten
4314      }
4315  
4316      /** Test long recursive chains of CompletableFutures with cascading completions */
4317 +    @SuppressWarnings("FutureReturnValueIgnored")
4318      public void testRecursiveChains() throws Throwable {
4319          for (ExecutionMode m : ExecutionMode.values())
4320          for (boolean addDeadEnds : new boolean[] { true, false })
# Line 4319 | Line 4339 | public class CompletableFutureTest exten
4339       * A single CompletableFuture with many dependents.
4340       * A demo of scalability - runtime is O(n).
4341       */
4342 +    @SuppressWarnings("FutureReturnValueIgnored")
4343      public void testManyDependents() throws Throwable {
4344          final int n = expensiveTests ? 1_000_000 : 10;
4345          final CompletableFuture<Void> head = new CompletableFuture<>();
# Line 4348 | Line 4369 | public class CompletableFutureTest exten
4369      }
4370  
4371      /** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */
4372 +    @SuppressWarnings("FutureReturnValueIgnored")
4373      public void testCoCompletionGarbageRetention() throws Throwable {
4374          final int n = expensiveTests ? 1_000_000 : 10;
4375          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines