|
16 | 16 | package rx.observers;
|
17 | 17 |
|
18 | 18 | import static org.junit.Assert.assertEquals;
|
| 19 | +import static org.junit.Assert.assertTrue; |
19 | 20 | import static org.mockito.Mockito.inOrder;
|
20 | 21 | import static org.mockito.Mockito.mock;
|
21 | 22 | import static org.mockito.Mockito.times;
|
22 | 23 |
|
23 | 24 | import java.util.Arrays;
|
| 25 | +import java.util.concurrent.TimeUnit; |
| 26 | +import java.util.concurrent.atomic.AtomicBoolean; |
24 | 27 |
|
| 28 | +import org.junit.Assert; |
25 | 29 | import org.junit.Rule;
|
26 | 30 | import org.junit.Test;
|
27 | 31 | import org.junit.rules.ExpectedException;
|
28 | 32 | import org.mockito.InOrder;
|
29 | 33 |
|
30 | 34 | import rx.Observable;
|
31 | 35 | import rx.Observer;
|
| 36 | +import rx.functions.Action0; |
32 | 37 | import rx.subjects.PublishSubject;
|
33 | 38 |
|
34 | 39 | public class TestSubscriberTest {
|
@@ -124,8 +129,35 @@ public void testWrappingMockWhenUnsubscribeInvolved() {
|
124 | 129 | @Test
|
125 | 130 | public void testAssertError() {
|
126 | 131 | RuntimeException e = new RuntimeException("Oops");
|
127 |
| - TestSubscriber subscriber = new TestSubscriber(); |
| 132 | + TestSubscriber<Object> subscriber = new TestSubscriber<Object>(); |
128 | 133 | Observable.error(e).subscribe(subscriber);
|
129 | 134 | subscriber.assertError(e);
|
130 | 135 | }
|
| 136 | + |
| 137 | + @Test |
| 138 | + public void testAwaitTerminalEventWithDuration() { |
| 139 | + TestSubscriber<Object> ts = new TestSubscriber<Object>(); |
| 140 | + Observable.just(1).subscribe(ts); |
| 141 | + ts.awaitTerminalEvent(1, TimeUnit.SECONDS); |
| 142 | + ts.assertTerminalEvent(); |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + public void testAwaitTerminalEventWithDurationAndUnsubscribeOnTimeout() { |
| 147 | + TestSubscriber<Object> ts = new TestSubscriber<Object>(); |
| 148 | + final AtomicBoolean unsub = new AtomicBoolean(false); |
| 149 | + Observable.just(1) |
| 150 | + // |
| 151 | + .doOnUnsubscribe(new Action0() { |
| 152 | + @Override |
| 153 | + public void call() { |
| 154 | + unsub.set(true); |
| 155 | + } |
| 156 | + }) |
| 157 | + // |
| 158 | + .delay(1000, TimeUnit.MILLISECONDS).subscribe(ts); |
| 159 | + ts.awaitTerminalEventAndUnsubscribeOnTimeout(100, TimeUnit.MILLISECONDS); |
| 160 | + assertTrue(unsub.get()); |
| 161 | + } |
| 162 | + |
131 | 163 | }
|
0 commit comments