|
1 | 1 | /** |
2 | 2 | * Copyright 2015 Netflix, Inc. |
3 | | - * |
| 3 | + * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
5 | 5 | * compliance with the License. You may obtain a copy of the License at |
6 | | - * |
| 6 | + * |
7 | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
8 | | - * |
| 8 | + * |
9 | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is |
10 | 10 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
11 | 11 | * the License for the specific language governing permissions and limitations under the License. |
@@ -1182,6 +1182,42 @@ public void doAfterTerminateActionShouldNotBeInvokedUntilSubscriberSubscribes() |
1182 | 1182 | verifyZeroInteractions(action); |
1183 | 1183 | } |
1184 | 1184 |
|
| 1185 | + @Test |
| 1186 | + public void onErrorResumeNextViaSingleShouldNotInterruptSuccessfulSingle() { |
| 1187 | + TestSubscriber<String> testSubscriber = new TestSubscriber<String>(); |
| 1188 | + |
| 1189 | + Single |
| 1190 | + .just("success") |
| 1191 | + .onErrorResumeNext(Single.just("fail")) |
| 1192 | + .subscribe(testSubscriber); |
| 1193 | + |
| 1194 | + testSubscriber.assertValue("success"); |
| 1195 | + } |
| 1196 | + |
| 1197 | + @Test |
| 1198 | + public void onErrorResumeNextViaSingleShouldResumeWithPassedSingleInCaseOfError() { |
| 1199 | + TestSubscriber<String> testSubscriber = new TestSubscriber<String>(); |
| 1200 | + |
| 1201 | + Single |
| 1202 | + .<String>error(new RuntimeException("test exception")) |
| 1203 | + .onErrorResumeNext(Single.just("fallback")) |
| 1204 | + .subscribe(testSubscriber); |
| 1205 | + |
| 1206 | + testSubscriber.assertValue("fallback"); |
| 1207 | + } |
| 1208 | + |
| 1209 | + @Test |
| 1210 | + public void onErrorResumeNextViaSingleShouldPreventNullSingle() { |
| 1211 | + try { |
| 1212 | + Single |
| 1213 | + .just("value") |
| 1214 | + .onErrorResumeNext(null); |
| 1215 | + fail(); |
| 1216 | + } catch (NullPointerException expected) { |
| 1217 | + assertEquals("resumeSingleInCaseOfError must not be null", expected.getMessage()); |
| 1218 | + } |
| 1219 | + } |
| 1220 | + |
1185 | 1221 | @Test(expected = NullPointerException.class) |
1186 | 1222 | public void iterableToArrayShouldThrowNullPointerExceptionIfIterableNull() { |
1187 | 1223 | Single.iterableToArray(null); |
|
0 commit comments