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.189 by jsr166, Sat Oct 21 06:51:52 2017 UTC vs.
Revision 1.197 by jsr166, Sun Jul 22 22:08:49 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 60 | Line 59 | public class CompletableFutureTest exten
59          assertFalse(f.isDone());
60          assertFalse(f.isCancelled());
61          assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
62 +
63 +        Object result = null;
64          try {
65 <            assertNull(f.getNow(null));
66 <        } catch (Exception fail) { threadUnexpectedException(fail); }
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 71 | Line 74 | public class CompletableFutureTest exten
74          catch (Throwable fail) { threadUnexpectedException(fail); }
75      }
76  
77 <    <T> void checkCompletedNormally(CompletableFuture<T> f, T value) {
78 <        checkTimedGet(f, value);
77 >    <T> void checkCompletedNormally(CompletableFuture<T> f, T expectedValue) {
78 >        checkTimedGet(f, expectedValue);
79 >
80 >        assertEquals(expectedValue, f.join());
81 >        assertEquals(expectedValue, f.getNow(null));
82  
83 +        T result = null;
84          try {
85 <            assertEquals(value, f.join());
86 <            assertEquals(value, f.getNow(null));
87 <            assertEquals(value, f.get());
88 <        } catch (Exception fail) { threadUnexpectedException(fail); }
85 >            result = f.get();
86 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
87 >        assertEquals(expectedValue, result);
88 >
89          assertTrue(f.isDone());
90          assertFalse(f.isCancelled());
91          assertFalse(f.isCompletedExceptionally());
# Line 292 | Line 299 | public class CompletableFutureTest exten
299          }
300  
301          f = new CompletableFuture<>();
302 <        f.completeExceptionally(ex = new CFException());
302 >        f.completeExceptionally(new CFException());
303          f.obtrudeValue(v1);
304          checkCompletedNormally(f, v1);
305          f.obtrudeException(ex = new CFException());
# Line 330 | Line 337 | public class CompletableFutureTest exten
337       * toString indicates current completion state
338       */
339      public void testToString_incomplete() {
340 <        CompletableFuture<String> f = new CompletableFuture<String>();
340 >        CompletableFuture<String> f = new CompletableFuture<>();
341          assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
342          if (testImplementationDetails)
343              assertEquals(identityString(f) + "[Not completed]",
# Line 338 | Line 345 | public class CompletableFutureTest exten
345      }
346  
347      public void testToString_normal() {
348 <        CompletableFuture<String> f = new CompletableFuture<String>();
348 >        CompletableFuture<String> f = new CompletableFuture<>();
349          assertTrue(f.complete("foo"));
350          assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
351          if (testImplementationDetails)
# Line 347 | Line 354 | public class CompletableFutureTest exten
354      }
355  
356      public void testToString_exception() {
357 <        CompletableFuture<String> f = new CompletableFuture<String>();
357 >        CompletableFuture<String> f = new CompletableFuture<>();
358          assertTrue(f.completeExceptionally(new IndexOutOfBoundsException()));
359          assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
360          if (testImplementationDetails)
# Line 357 | Line 364 | public class CompletableFutureTest exten
364  
365      public void testToString_cancelled() {
366          for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
367 <            CompletableFuture<String> f = new CompletableFuture<String>();
367 >            CompletableFuture<String> f = new CompletableFuture<>();
368              assertTrue(f.cancel(mayInterruptIfRunning));
369              assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
370              if (testImplementationDetails)
# Line 4190 | Line 4197 | public class CompletableFutureTest exten
4197          static void assertZero(CompletableFuture<?> f) {
4198              try {
4199                  f.getNow(null);
4200 <                throw new AssertionFailedError("should throw");
4200 >                throw new AssertionError("should throw");
4201              } catch (CompletionException success) {
4202                  assertTrue(success.getCause() instanceof ZeroException);
4203              }
# Line 4389 | Line 4396 | public class CompletableFutureTest exten
4396              f.complete(null);
4397  
4398              f = new CompletableFuture<>();
4399 <            CompletableFuture.anyOf(new CompletableFuture<?>[] { f, incomplete });
4399 >            CompletableFuture.anyOf(f, incomplete);
4400              f.complete(null);
4401          }
4402  
# Line 4407 | Line 4414 | public class CompletableFutureTest exten
4414              f.complete(null);
4415  
4416              f = new CompletableFuture<>();
4417 <            CompletableFuture.anyOf(new CompletableFuture<?>[] { incomplete, f });
4417 >            CompletableFuture.anyOf(incomplete, f);
4418              f.complete(null);
4419          }
4420      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines