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 |
|
|
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)); |
65 |
> |
result = f.getNow(null); |
66 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
67 |
+ |
assertNull(result); |
68 |
+ |
|
69 |
|
try { |
70 |
|
f.get(randomExpiredTimeout(), randomTimeUnit()); |
71 |
|
shouldThrow(); |
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()); |
333 |
|
* toString indicates current completion state |
334 |
|
*/ |
335 |
|
public void testToString_incomplete() { |
336 |
< |
CompletableFuture<String> f = new CompletableFuture<String>(); |
336 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
337 |
|
assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]")); |
338 |
|
if (testImplementationDetails) |
339 |
|
assertEquals(identityString(f) + "[Not completed]", |
341 |
|
} |
342 |
|
|
343 |
|
public void testToString_normal() { |
344 |
< |
CompletableFuture<String> f = new CompletableFuture<String>(); |
344 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
345 |
|
assertTrue(f.complete("foo")); |
346 |
|
assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]")); |
347 |
|
if (testImplementationDetails) |
350 |
|
} |
351 |
|
|
352 |
|
public void testToString_exception() { |
353 |
< |
CompletableFuture<String> f = new CompletableFuture<String>(); |
353 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
354 |
|
assertTrue(f.completeExceptionally(new IndexOutOfBoundsException())); |
355 |
|
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); |
356 |
|
if (testImplementationDetails) |
360 |
|
|
361 |
|
public void testToString_cancelled() { |
362 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
363 |
< |
CompletableFuture<String> f = new CompletableFuture<String>(); |
363 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
364 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
365 |
|
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); |
366 |
|
if (testImplementationDetails) |
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 |
|
} |
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 |
|
|
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 |
|
} |