|
19 | 19 | import static org.mockito.Matchers.*;
|
20 | 20 | import static org.mockito.Mockito.*;
|
21 | 21 |
|
22 |
| -import java.util.Arrays; |
| 22 | +import java.util.*; |
23 | 23 | import java.util.concurrent.*;
|
24 | 24 | import java.util.concurrent.atomic.*;
|
25 | 25 |
|
26 | 26 | import org.junit.Test;
|
27 | 27 | import org.mockito.InOrder;
|
28 | 28 |
|
29 | 29 | import rx.*;
|
| 30 | +import rx.Observable; |
30 | 31 | import rx.Observable.OnSubscribe;
|
| 32 | +import rx.Observer; |
31 | 33 | import rx.exceptions.TestException;
|
32 | 34 | import rx.functions.*;
|
33 | 35 | import rx.observers.*;
|
| 36 | +import rx.plugins.RxJavaHooks; |
34 | 37 | import rx.schedulers.Schedulers;
|
35 | 38 | import rx.subjects.PublishSubject;
|
36 | 39 |
|
@@ -457,4 +460,39 @@ public void takeZero() {
|
457 | 460 | ts.assertCompleted();
|
458 | 461 | }
|
459 | 462 |
|
| 463 | + @Test |
| 464 | + public void crashReportedToHooks() { |
| 465 | + final List<Throwable> errors = Collections.synchronizedList(new ArrayList<Throwable>()); |
| 466 | + RxJavaHooks.setOnError(new Action1<Throwable>() { |
| 467 | + @Override |
| 468 | + public void call(Throwable error) { |
| 469 | + errors.add(error); |
| 470 | + } |
| 471 | + }); |
| 472 | + |
| 473 | + try { |
| 474 | + Observable.just("1") |
| 475 | + .take(1) |
| 476 | + .toSingle() |
| 477 | + .subscribe( |
| 478 | + new Action1<String>() { |
| 479 | + @Override |
| 480 | + public void call(String it) { |
| 481 | + throw new TestException("bla"); |
| 482 | + } |
| 483 | + }, |
| 484 | + new Action1<Throwable>() { |
| 485 | + @Override |
| 486 | + public void call(Throwable error) { |
| 487 | + errors.add(new AssertionError()); |
| 488 | + } |
| 489 | + } |
| 490 | + ); |
| 491 | + |
| 492 | + assertEquals("" + errors, 1, errors.size()); |
| 493 | + assertTrue("" + errors.get(0), errors.get(0).getMessage().equals("bla")); |
| 494 | + } finally { |
| 495 | + RxJavaHooks.setOnError(null); |
| 496 | + } |
| 497 | + } |
460 | 498 | }
|
0 commit comments