|
26 | 26 |
|
27 | 27 | import io.reactivex.*;
|
28 | 28 | import io.reactivex.exceptions.*;
|
| 29 | +import io.reactivex.flowables.ConnectableFlowable; |
29 | 30 | import io.reactivex.functions.*;
|
30 | 31 | import io.reactivex.internal.functions.Functions;
|
31 | 32 | import io.reactivex.internal.fuseable.*;
|
@@ -732,4 +733,197 @@ public Flowable<Object> apply(Flowable<Object> o) throws Exception {
|
732 | 733 | }
|
733 | 734 | });
|
734 | 735 | }
|
| 736 | + |
| 737 | + @Test |
| 738 | + public void doOnNextDoOnErrorFused() { |
| 739 | + ConnectableFlowable<Integer> co = Flowable.just(1) |
| 740 | + .doOnNext(new Consumer<Integer>() { |
| 741 | + @Override |
| 742 | + public void accept(Integer v) throws Exception { |
| 743 | + throw new TestException("First"); |
| 744 | + } |
| 745 | + }) |
| 746 | + .doOnError(new Consumer<Throwable>() { |
| 747 | + @Override |
| 748 | + public void accept(Throwable e) throws Exception { |
| 749 | + throw new TestException("Second"); |
| 750 | + } |
| 751 | + }) |
| 752 | + .publish(); |
| 753 | + |
| 754 | + TestSubscriber<Integer> ts = co.test(); |
| 755 | + co.connect(); |
| 756 | + |
| 757 | + ts.assertFailure(CompositeException.class); |
| 758 | + |
| 759 | + TestHelper.assertError(ts, 0, TestException.class, "First"); |
| 760 | + TestHelper.assertError(ts, 1, TestException.class, "Second"); |
| 761 | + } |
| 762 | + |
| 763 | + @Test |
| 764 | + public void doOnNextDoOnErrorCombinedFused() { |
| 765 | + ConnectableFlowable<Integer> co = Flowable.just(1) |
| 766 | + .compose(new FlowableTransformer<Integer, Integer>() { |
| 767 | + @Override |
| 768 | + public Publisher<Integer> apply(Flowable<Integer> v) { |
| 769 | + return new FlowableDoOnEach<Integer>(v, |
| 770 | + new Consumer<Integer>() { |
| 771 | + @Override |
| 772 | + public void accept(Integer v) throws Exception { |
| 773 | + throw new TestException("First"); |
| 774 | + } |
| 775 | + }, |
| 776 | + new Consumer<Throwable>() { |
| 777 | + @Override |
| 778 | + public void accept(Throwable e) throws Exception { |
| 779 | + throw new TestException("Second"); |
| 780 | + } |
| 781 | + }, |
| 782 | + Functions.EMPTY_ACTION |
| 783 | + , |
| 784 | + Functions.EMPTY_ACTION |
| 785 | + ); |
| 786 | + } |
| 787 | + }) |
| 788 | + .publish(); |
| 789 | + |
| 790 | + TestSubscriber<Integer> ts = co.test(); |
| 791 | + co.connect(); |
| 792 | + |
| 793 | + ts.assertFailure(CompositeException.class); |
| 794 | + |
| 795 | + TestHelper.assertError(ts, 0, TestException.class, "First"); |
| 796 | + TestHelper.assertError(ts, 1, TestException.class, "Second"); |
| 797 | + } |
| 798 | + |
| 799 | + @Test |
| 800 | + public void doOnNextDoOnErrorFused2() { |
| 801 | + ConnectableFlowable<Integer> co = Flowable.just(1) |
| 802 | + .doOnNext(new Consumer<Integer>() { |
| 803 | + @Override |
| 804 | + public void accept(Integer v) throws Exception { |
| 805 | + throw new TestException("First"); |
| 806 | + } |
| 807 | + }) |
| 808 | + .doOnError(new Consumer<Throwable>() { |
| 809 | + @Override |
| 810 | + public void accept(Throwable e) throws Exception { |
| 811 | + throw new TestException("Second"); |
| 812 | + } |
| 813 | + }) |
| 814 | + .doOnError(new Consumer<Throwable>() { |
| 815 | + @Override |
| 816 | + public void accept(Throwable e) throws Exception { |
| 817 | + throw new TestException("Third"); |
| 818 | + } |
| 819 | + }) |
| 820 | + .publish(); |
| 821 | + |
| 822 | + TestSubscriber<Integer> ts = co.test(); |
| 823 | + co.connect(); |
| 824 | + |
| 825 | + ts.assertFailure(CompositeException.class); |
| 826 | + |
| 827 | + TestHelper.assertError(ts, 0, TestException.class, "First"); |
| 828 | + TestHelper.assertError(ts, 1, TestException.class, "Second"); |
| 829 | + TestHelper.assertError(ts, 2, TestException.class, "Third"); |
| 830 | + } |
| 831 | + |
| 832 | + @Test |
| 833 | + public void doOnNextDoOnErrorFusedConditional() { |
| 834 | + ConnectableFlowable<Integer> co = Flowable.just(1) |
| 835 | + .doOnNext(new Consumer<Integer>() { |
| 836 | + @Override |
| 837 | + public void accept(Integer v) throws Exception { |
| 838 | + throw new TestException("First"); |
| 839 | + } |
| 840 | + }) |
| 841 | + .doOnError(new Consumer<Throwable>() { |
| 842 | + @Override |
| 843 | + public void accept(Throwable e) throws Exception { |
| 844 | + throw new TestException("Second"); |
| 845 | + } |
| 846 | + }) |
| 847 | + .filter(Functions.alwaysTrue()) |
| 848 | + .publish(); |
| 849 | + |
| 850 | + TestSubscriber<Integer> ts = co.test(); |
| 851 | + co.connect(); |
| 852 | + |
| 853 | + ts.assertFailure(CompositeException.class); |
| 854 | + |
| 855 | + TestHelper.assertError(ts, 0, TestException.class, "First"); |
| 856 | + TestHelper.assertError(ts, 1, TestException.class, "Second"); |
| 857 | + } |
| 858 | + |
| 859 | + @Test |
| 860 | + public void doOnNextDoOnErrorFusedConditional2() { |
| 861 | + ConnectableFlowable<Integer> co = Flowable.just(1) |
| 862 | + .doOnNext(new Consumer<Integer>() { |
| 863 | + @Override |
| 864 | + public void accept(Integer v) throws Exception { |
| 865 | + throw new TestException("First"); |
| 866 | + } |
| 867 | + }) |
| 868 | + .doOnError(new Consumer<Throwable>() { |
| 869 | + @Override |
| 870 | + public void accept(Throwable e) throws Exception { |
| 871 | + throw new TestException("Second"); |
| 872 | + } |
| 873 | + }) |
| 874 | + .doOnError(new Consumer<Throwable>() { |
| 875 | + @Override |
| 876 | + public void accept(Throwable e) throws Exception { |
| 877 | + throw new TestException("Third"); |
| 878 | + } |
| 879 | + }) |
| 880 | + .filter(Functions.alwaysTrue()) |
| 881 | + .publish(); |
| 882 | + |
| 883 | + TestSubscriber<Integer> ts = co.test(); |
| 884 | + co.connect(); |
| 885 | + |
| 886 | + ts.assertFailure(CompositeException.class); |
| 887 | + |
| 888 | + TestHelper.assertError(ts, 0, TestException.class, "First"); |
| 889 | + TestHelper.assertError(ts, 1, TestException.class, "Second"); |
| 890 | + TestHelper.assertError(ts, 2, TestException.class, "Third"); |
| 891 | + } |
| 892 | + |
| 893 | + @Test |
| 894 | + public void doOnNextDoOnErrorCombinedFusedConditional() { |
| 895 | + ConnectableFlowable<Integer> co = Flowable.just(1) |
| 896 | + .compose(new FlowableTransformer<Integer, Integer>() { |
| 897 | + @Override |
| 898 | + public Publisher<Integer> apply(Flowable<Integer> v) { |
| 899 | + return new FlowableDoOnEach<Integer>(v, |
| 900 | + new Consumer<Integer>() { |
| 901 | + @Override |
| 902 | + public void accept(Integer v) throws Exception { |
| 903 | + throw new TestException("First"); |
| 904 | + } |
| 905 | + }, |
| 906 | + new Consumer<Throwable>() { |
| 907 | + @Override |
| 908 | + public void accept(Throwable e) throws Exception { |
| 909 | + throw new TestException("Second"); |
| 910 | + } |
| 911 | + }, |
| 912 | + Functions.EMPTY_ACTION |
| 913 | + , |
| 914 | + Functions.EMPTY_ACTION |
| 915 | + ); |
| 916 | + } |
| 917 | + }) |
| 918 | + .filter(Functions.alwaysTrue()) |
| 919 | + .publish(); |
| 920 | + |
| 921 | + TestSubscriber<Integer> ts = co.test(); |
| 922 | + co.connect(); |
| 923 | + |
| 924 | + ts.assertFailure(CompositeException.class); |
| 925 | + |
| 926 | + TestHelper.assertError(ts, 0, TestException.class, "First"); |
| 927 | + TestHelper.assertError(ts, 1, TestException.class, "Second"); |
| 928 | + } |
735 | 929 | }
|
0 commit comments