forked from jhusain/learnrxjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTesting.java
More file actions
29 lines (21 loc) · 857 Bytes
/
UnitTesting.java
File metadata and controls
29 lines (21 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package learnrxjava.examples;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.observers.TestSubscriber;
import rx.schedulers.Schedulers;
import rx.schedulers.TestScheduler;
public class UnitTesting {
public static void main(String... args) {
TestScheduler test = Schedulers.test();
TestSubscriber<String> ts = new TestSubscriber<>();
Observable.interval(200, TimeUnit.MILLISECONDS, test)
.map(i -> {
return i + " value";
}).subscribe(ts);
test.advanceTimeBy(200, TimeUnit.MILLISECONDS);
ts.assertReceivedOnNext(Arrays.asList("0 value"));
test.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
ts.assertReceivedOnNext(Arrays.asList("0 value", "1 value", "2 value", "3 value", "4 value"));
}
}