|
51 | 51 | import rx.schedulers.Schedulers; |
52 | 52 | import rx.subscriptions.Subscriptions; |
53 | 53 |
|
54 | | - |
55 | 54 | public class SingleTest { |
56 | 55 |
|
57 | 56 | @Test |
@@ -891,4 +890,55 @@ public void call(SingleSubscriber<? super Object> singleSubscriber) { |
891 | 890 | testSubscriber.assertNoValues(); |
892 | 891 | testSubscriber.assertNoTerminalEvent(); |
893 | 892 | } |
| 893 | + |
| 894 | + @Test |
| 895 | + public void doAfterTerminateActionShouldBeInvokedAfterOnSuccess() { |
| 896 | + Action0 action = mock(Action0.class); |
| 897 | + |
| 898 | + TestSubscriber<String> testSubscriber = new TestSubscriber<String>(); |
| 899 | + |
| 900 | + Single |
| 901 | + .just("value") |
| 902 | + .doAfterTerminate(action) |
| 903 | + .subscribe(testSubscriber); |
| 904 | + |
| 905 | + testSubscriber.assertValue("value"); |
| 906 | + testSubscriber.assertNoErrors(); |
| 907 | + |
| 908 | + verify(action).call(); |
| 909 | + } |
| 910 | + |
| 911 | + @Test |
| 912 | + public void doAfterTerminateActionShouldBeInvokedAfterOnError() { |
| 913 | + Action0 action = mock(Action0.class); |
| 914 | + |
| 915 | + TestSubscriber<Object> testSubscriber = new TestSubscriber<Object>(); |
| 916 | + |
| 917 | + Throwable error = new IllegalStateException(); |
| 918 | + |
| 919 | + Single |
| 920 | + .error(error) |
| 921 | + .doAfterTerminate(action) |
| 922 | + .subscribe(testSubscriber); |
| 923 | + |
| 924 | + testSubscriber.assertNoValues(); |
| 925 | + testSubscriber.assertError(error); |
| 926 | + |
| 927 | + verify(action).call(); |
| 928 | + } |
| 929 | + |
| 930 | + @Test |
| 931 | + public void doAfterTerminateActionShouldNotBeInvokedUntilSubscriberSubscribes() { |
| 932 | + Action0 action = mock(Action0.class); |
| 933 | + |
| 934 | + Single |
| 935 | + .just("value") |
| 936 | + .doAfterTerminate(action); |
| 937 | + |
| 938 | + Single |
| 939 | + .error(new IllegalStateException()) |
| 940 | + .doAfterTerminate(action); |
| 941 | + |
| 942 | + verifyZeroInteractions(action); |
| 943 | + } |
894 | 944 | } |
0 commit comments