|
18 | 18 | import static org.junit.Assert.assertEquals;
|
19 | 19 | import static org.junit.Assert.assertNotNull;
|
20 | 20 | import static org.junit.Assert.assertNotSame;
|
21 |
| -import static org.mockito.Matchers.isA; |
22 |
| -import static org.mockito.Mockito.inOrder; |
23 |
| -import static org.mockito.Mockito.spy; |
24 |
| -import static org.mockito.Mockito.times; |
| 21 | +import static org.junit.Assert.assertTrue; |
25 | 22 |
|
26 | 23 | import java.util.Arrays;
|
27 | 24 | import java.util.concurrent.CountDownLatch;
|
28 | 25 | import java.util.concurrent.atomic.AtomicReference;
|
29 | 26 |
|
30 | 27 | import org.junit.Test;
|
31 |
| -import org.mockito.InOrder; |
32 | 28 |
|
33 | 29 | import rx.Observable;
|
34 | 30 | import rx.Observable.OnSubscribe;
|
35 |
| -import rx.Scheduler; |
36 | 31 | import rx.Subscriber;
|
37 | 32 | import rx.Subscription;
|
38 | 33 | import rx.observers.TestObserver;
|
39 | 34 | import rx.schedulers.Schedulers;
|
40 | 35 | import rx.subscriptions.Subscriptions;
|
41 |
| -import rx.test.OperatorTester; |
42 | 36 | import rx.util.functions.Action0;
|
43 |
| -import rx.util.functions.Action1; |
44 | 37 |
|
45 | 38 | public class OperatorSubscribeOnTest {
|
46 | 39 |
|
47 |
| - @Test |
48 |
| - @SuppressWarnings("unchecked") |
49 |
| - public void testSubscribeOn() { |
50 |
| - Observable<Integer> w = Observable.from(Arrays.asList(1, 2, 3)); |
51 |
| - |
52 |
| - Scheduler scheduler = spy(OperatorTester.forwardingScheduler(Schedulers |
53 |
| - .immediate())); |
54 |
| - |
55 |
| - TestObserver<Integer> observer = new TestObserver<Integer>(); |
56 |
| - w.subscribeOn(scheduler).subscribe(observer); |
57 |
| - |
58 |
| - InOrder inOrder = inOrder(scheduler); |
59 |
| - // The first one is for "subscribe", the second one is for |
60 |
| - // "unsubscribe". |
61 |
| - inOrder.verify(scheduler, times(2)).schedule(isA(Action1.class)); |
62 |
| - inOrder.verifyNoMoreInteractions(); |
63 |
| - |
64 |
| - observer.assertReceivedOnNext(Arrays.asList(1, 2, 3)); |
65 |
| - observer.assertTerminalEvent(); |
66 |
| - } |
67 |
| - |
68 | 40 | private class ThreadSubscription implements Subscription {
|
69 | 41 | private volatile Thread thread;
|
70 | 42 |
|
@@ -114,15 +86,17 @@ public void call(Subscriber<? super Integer> t1) {
|
114 | 86 | });
|
115 | 87 |
|
116 | 88 | TestObserver<Integer> observer = new TestObserver<Integer>();
|
117 |
| - w.subscribeOn(Schedulers.computation()).subscribe(observer); |
| 89 | + w.subscribeOn(Schedulers.newThread()).subscribe(observer); |
118 | 90 |
|
119 | 91 | Thread unsubscribeThread = subscription.getThread();
|
120 | 92 |
|
121 | 93 | assertNotNull(unsubscribeThread);
|
122 | 94 | assertNotSame(Thread.currentThread(), unsubscribeThread);
|
123 | 95 |
|
124 |
| - assertNotNull(subscribeThread); |
125 |
| - assertNotSame(Thread.currentThread(), subscribeThread); |
| 96 | + assertNotNull(subscribeThread.get()); |
| 97 | + assertNotSame(Thread.currentThread(), subscribeThread.get()); |
| 98 | + // True for Schedulers.newThread() |
| 99 | + assertTrue(unsubscribeThread == subscribeThread.get()); |
126 | 100 |
|
127 | 101 | observer.assertReceivedOnNext(Arrays.asList(1, 2));
|
128 | 102 | observer.assertTerminalEvent();
|
|
0 commit comments