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> observable = Observable .just("a", "b", "c", "d", "e") .lift(new Indexed()); List> expected = Arrays.asList( new Pair(0L, "a"), new Pair(1L, "b"), new Pair(2L, "c"), new Pair(3L, "d"), new Pair(4L, "e") ); List> actual = observable .toList() .toBlocking(). single(); assertEquals(expected, actual); // The same result the second time around TestSubscriber> testSubscriber = new TestSubscriber>(); observable.subscribe(testSubscriber); testSubscriber.assertReceivedOnNext(expected); } }