-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathIndexedTest.java
52 lines (38 loc) · 1.2 KB
/
IndexedTest.java
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.packtpub.reactive.chapter08;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import rx.Observable;
import rx.observers.TestSubscriber;
import com.packtpub.reactive.chapter08.Lift.Indexed;
import com.packtpub.reactive.chapter08.Lift.Pair;
/**
* Tests the {@link Indexed} operator.
*
* @author meddle
*/
public class IndexedTest {
@Test
public void testGeneratesSequentialIndexes() {
Observable<Pair<Long, String>> observable = Observable
.just("a", "b", "c", "d", "e")
.lift(new Indexed<String>());
List<Pair<Long, String>> expected = Arrays.asList(
new Pair<Long, String>(0L, "a"),
new Pair<Long, String>(1L, "b"),
new Pair<Long, String>(2L, "c"),
new Pair<Long, String>(3L, "d"),
new Pair<Long, String>(4L, "e")
);
List<Pair<Long, String>> actual = observable
.toList()
.toBlocking().
single();
assertEquals(expected, actual);
// The same result the second time around
TestSubscriber<Pair<Long, String>> testSubscriber = new TestSubscriber<Pair<Long, String>>();
observable.subscribe(testSubscriber);
testSubscriber.assertReceivedOnNext(expected);
}
}