|
15 | 15 | */
|
16 | 16 | package rx.observers;
|
17 | 17 |
|
| 18 | +import static org.junit.Assert.assertEquals; |
18 | 19 | import static org.junit.Assert.assertTrue;
|
19 | 20 |
|
20 | 21 | import java.lang.reflect.Method;
|
| 22 | +import java.util.concurrent.atomic.AtomicInteger; |
21 | 23 |
|
22 |
| -import org.junit.*; |
| 24 | +import org.junit.After; |
| 25 | +import org.junit.Assert; |
| 26 | +import org.junit.Before; |
| 27 | +import org.junit.Test; |
23 | 28 |
|
24 |
| -import rx.exceptions.*; |
| 29 | +import rx.exceptions.OnErrorFailedException; |
| 30 | +import rx.exceptions.OnErrorNotImplementedException; |
| 31 | +import rx.exceptions.TestException; |
25 | 32 | import rx.functions.Action0;
|
26 |
| -import rx.plugins.*; |
| 33 | +import rx.plugins.RxJavaErrorHandler; |
| 34 | +import rx.plugins.RxJavaPlugins; |
27 | 35 | import rx.subscriptions.Subscriptions;
|
28 | 36 |
|
29 | 37 | public class SafeSubscriberTest {
|
@@ -227,4 +235,34 @@ public void call() {
|
227 | 235 |
|
228 | 236 | safe.onError(new TestException());
|
229 | 237 | }
|
| 238 | + |
| 239 | + @Test |
| 240 | + public void testPluginErrorHandlerReceivesExceptionWhenUnsubscribeAfterCompletionThrows() { |
| 241 | + final AtomicInteger calls = new AtomicInteger(); |
| 242 | + RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() { |
| 243 | + @Override |
| 244 | + public void handleError(Throwable e) { |
| 245 | + calls.incrementAndGet(); |
| 246 | + } |
| 247 | + }); |
| 248 | + |
| 249 | + final AtomicInteger errors = new AtomicInteger(); |
| 250 | + TestSubscriber<Integer> ts = new TestSubscriber<Integer>() { |
| 251 | + @Override |
| 252 | + public void onError(Throwable e) { |
| 253 | + errors.incrementAndGet(); |
| 254 | + } |
| 255 | + }; |
| 256 | + SafeSubscriber<Integer> safe = new SafeSubscriber<Integer>(ts); |
| 257 | + safe.add(Subscriptions.create(new Action0() { |
| 258 | + @Override |
| 259 | + public void call() { |
| 260 | + throw new RuntimeException(); |
| 261 | + } |
| 262 | + })); |
| 263 | + |
| 264 | + safe.onCompleted(); |
| 265 | + assertEquals(1, (int) calls.get()); |
| 266 | + assertEquals(0, (int) errors.get()); |
| 267 | + } |
230 | 268 | }
|
0 commit comments