355 |
|
} |
356 |
|
|
357 |
|
static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> { |
358 |
+ |
boolean ran; |
359 |
|
public Integer apply(Integer x, Throwable t) { |
360 |
+ |
ran = true; |
361 |
|
return (t == null) ? two : three; |
362 |
|
} |
363 |
|
} |
386 |
|
* normal or exceptional completion of source |
387 |
|
*/ |
388 |
|
public void testHandle() { |
389 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
390 |
< |
IntegerHandler r = new IntegerHandler(); |
391 |
< |
CompletableFuture<Integer> g = f.handle(r); |
389 |
> |
CompletableFuture<Integer> f, g; |
390 |
> |
IntegerHandler r; |
391 |
> |
|
392 |
> |
f = new CompletableFuture<Integer>(); |
393 |
> |
f.completeExceptionally(new CFException()); |
394 |
> |
g = f.handle(r = new IntegerHandler()); |
395 |
> |
assertTrue(r.ran); |
396 |
> |
checkCompletedNormally(g, three); |
397 |
> |
|
398 |
> |
f = new CompletableFuture<Integer>(); |
399 |
> |
g = f.handle(r = new IntegerHandler()); |
400 |
> |
assertFalse(r.ran); |
401 |
|
f.completeExceptionally(new CFException()); |
402 |
|
checkCompletedNormally(g, three); |
403 |
+ |
assertTrue(r.ran); |
404 |
+ |
|
405 |
+ |
f = new CompletableFuture<Integer>(); |
406 |
+ |
f.complete(one); |
407 |
+ |
g = f.handle(r = new IntegerHandler()); |
408 |
+ |
assertTrue(r.ran); |
409 |
+ |
checkCompletedNormally(g, two); |
410 |
|
|
411 |
|
f = new CompletableFuture<Integer>(); |
412 |
< |
r = new IntegerHandler(); |
413 |
< |
g = f.handle(r); |
412 |
> |
g = f.handle(r = new IntegerHandler()); |
413 |
> |
assertFalse(r.ran); |
414 |
|
f.complete(one); |
415 |
+ |
assertTrue(r.ran); |
416 |
|
checkCompletedNormally(g, two); |
417 |
|
} |
418 |
|
|
2423 |
|
Runnable[] throwingActions = { |
2424 |
|
() -> { CompletableFuture.supplyAsync(null); }, |
2425 |
|
() -> { CompletableFuture.supplyAsync(null, exec); }, |
2426 |
< |
() -> { CompletableFuture.supplyAsync(() -> one, null); }, |
2426 |
> |
() -> { CompletableFuture.supplyAsync(supplyOne, null); }, |
2427 |
|
|
2428 |
|
() -> { CompletableFuture.runAsync(null); }, |
2429 |
|
() -> { CompletableFuture.runAsync(null, exec); }, |
2512 |
|
() -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); }, |
2513 |
|
() -> { CompletableFuture.anyOf(f, null); }, |
2514 |
|
() -> { CompletableFuture.anyOf(null, f); }, |
2496 |
– |
|
2497 |
– |
// TODO: Crashes javac with lambda-8-2013-03-31... |
2498 |
– |
//() -> { CompletableFuture<?> x = f.thenAccept(null); }, |
2499 |
– |
//() -> { CompletableFuture<Void> x = f.thenRun(null); }, |
2500 |
– |
//() -> { CompletableFuture<Integer> x = f.thenApply(() -> { ; }); }, |
2515 |
|
}; |
2516 |
|
|
2517 |
|
assertThrows(NullPointerException.class, throwingActions); |