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 |
|
|
329 |
|
* toString indicates current completion state |
330 |
|
*/ |
331 |
|
public void testToString_incomplete() { |
332 |
< |
CompletableFuture<String> f = new CompletableFuture<String>(); |
332 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
333 |
|
assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]")); |
334 |
|
if (testImplementationDetails) |
335 |
|
assertEquals(identityString(f) + "[Not completed]", |
337 |
|
} |
338 |
|
|
339 |
|
public void testToString_normal() { |
340 |
< |
CompletableFuture<String> f = new CompletableFuture<String>(); |
340 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
341 |
|
assertTrue(f.complete("foo")); |
342 |
|
assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]")); |
343 |
|
if (testImplementationDetails) |
346 |
|
} |
347 |
|
|
348 |
|
public void testToString_exception() { |
349 |
< |
CompletableFuture<String> f = new CompletableFuture<String>(); |
349 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
350 |
|
assertTrue(f.completeExceptionally(new IndexOutOfBoundsException())); |
351 |
|
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); |
352 |
|
if (testImplementationDetails) |
356 |
|
|
357 |
|
public void testToString_cancelled() { |
358 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
359 |
< |
CompletableFuture<String> f = new CompletableFuture<String>(); |
359 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
360 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
361 |
|
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); |
362 |
|
if (testImplementationDetails) |
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 |
|
} |