|
11 | 11 |
|
12 | 12 | package io.vertx.tests.future; |
13 | 13 |
|
14 | | -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
15 | | - |
16 | | -import io.vertx.core.Completable; |
17 | | -import io.vertx.core.CompositeFuture; |
18 | | -import io.vertx.core.Future; |
19 | | -import io.vertx.core.Promise; |
| 14 | +import io.vertx.core.*; |
20 | 15 | import io.vertx.core.impl.future.FutureImpl; |
21 | 16 | import io.vertx.test.core.Repeat; |
22 | | - |
23 | 17 | import org.assertj.core.api.ThrowableAssert.ThrowingCallable; |
24 | 18 | import org.junit.Test; |
25 | 19 |
|
|
29 | 23 | import java.util.concurrent.Executors; |
30 | 24 | import java.util.concurrent.TimeUnit; |
31 | 25 | import java.util.concurrent.atomic.AtomicInteger; |
32 | | -import java.util.function.BiConsumer; |
33 | | -import java.util.function.BiFunction; |
34 | | -import java.util.function.Consumer; |
35 | | -import java.util.function.Function; |
| 26 | +import java.util.function.*; |
36 | 27 | import java.util.stream.Collectors; |
37 | 28 | import java.util.stream.IntStream; |
38 | 29 |
|
| 30 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 31 | + |
39 | 32 | /** |
40 | 33 | * @author <a href="mailto:julien@julienviet.com">Julien Viet</a> |
41 | 34 | */ |
@@ -577,4 +570,103 @@ public void testAnyRemovesListeners2() { |
577 | 570 | Future.any(f, Future.succeededFuture()); |
578 | 571 | assertEquals(Collections.emptySet(), f.listeners); |
579 | 572 | } |
| 573 | + |
| 574 | + @Test |
| 575 | + public void testCustomFuture() { |
| 576 | + Promise<Void> p1 = Promise.promise(); |
| 577 | + Promise<Void> p2 = Promise.promise(); |
| 578 | + Promise<Void> p3 = Promise.promise(); |
| 579 | + |
| 580 | + CompositeFuture cf = Future.all(p1.future(), new MyFuture(p2), p3.future()); |
| 581 | + |
| 582 | + p1.complete(null); |
| 583 | + p2.complete(null); |
| 584 | + p3.complete(null); |
| 585 | + |
| 586 | + assertTrue(cf.isComplete()); |
| 587 | + } |
| 588 | + |
| 589 | + private static class MyFuture implements Future<Void> { |
| 590 | + |
| 591 | + private final Future<Void> delegate; |
| 592 | + |
| 593 | + private MyFuture(Promise<Void> promise) { |
| 594 | + delegate = promise.future(); |
| 595 | + } |
| 596 | + |
| 597 | + @Override |
| 598 | + public boolean isComplete() { |
| 599 | + return delegate.isComplete(); |
| 600 | + } |
| 601 | + |
| 602 | + @Override |
| 603 | + public Future<Void> onComplete(Handler<AsyncResult<Void>> handler) { |
| 604 | + return delegate.onComplete(handler); |
| 605 | + } |
| 606 | + |
| 607 | + @Override |
| 608 | + public Void result() { |
| 609 | + return delegate.result(); |
| 610 | + } |
| 611 | + |
| 612 | + @Override |
| 613 | + public Throwable cause() { |
| 614 | + return delegate.cause(); |
| 615 | + } |
| 616 | + |
| 617 | + @Override |
| 618 | + public boolean succeeded() { |
| 619 | + return delegate.succeeded(); |
| 620 | + } |
| 621 | + |
| 622 | + @Override |
| 623 | + public boolean failed() { |
| 624 | + return delegate.failed(); |
| 625 | + } |
| 626 | + |
| 627 | + @Override |
| 628 | + public <U> Future<U> compose(Function<? super Void, Future<U>> successMapper, Function<Throwable, Future<U>> failureMapper) { |
| 629 | + return delegate.compose(successMapper, failureMapper); |
| 630 | + } |
| 631 | + |
| 632 | + @Override |
| 633 | + public <U> Future<U> transform(Function<AsyncResult<Void>, Future<U>> mapper) { |
| 634 | + return delegate.transform(mapper); |
| 635 | + } |
| 636 | + |
| 637 | + @Override |
| 638 | + public <U> Future<Void> eventually(Supplier<Future<U>> mapper) { |
| 639 | + return delegate.eventually(mapper); |
| 640 | + } |
| 641 | + |
| 642 | + @Override |
| 643 | + public <U> Future<U> map(Function<? super Void, U> mapper) { |
| 644 | + return delegate.map(mapper); |
| 645 | + } |
| 646 | + |
| 647 | + @Override |
| 648 | + public <V> Future<V> map(V value) { |
| 649 | + return delegate.map(value); |
| 650 | + } |
| 651 | + |
| 652 | + @Override |
| 653 | + public Future<Void> otherwise(Function<Throwable, Void> mapper) { |
| 654 | + return delegate.otherwise(mapper); |
| 655 | + } |
| 656 | + |
| 657 | + @Override |
| 658 | + public Future<Void> otherwise(Void value) { |
| 659 | + return delegate.otherwise(value); |
| 660 | + } |
| 661 | + |
| 662 | + @Override |
| 663 | + public Future<Void> expecting(Expectation<? super Void> expectation) { |
| 664 | + return delegate.expecting(expectation); |
| 665 | + } |
| 666 | + |
| 667 | + @Override |
| 668 | + public Future<Void> timeout(long delay, TimeUnit unit) { |
| 669 | + return delegate.timeout(delay, unit); |
| 670 | + } |
| 671 | + } |
580 | 672 | } |
0 commit comments