@Override public Flowable<List<Object>> apply(Flowable<Object> f) throws Exception { return f.toList().toFlowable(); } });
@Test public void testList() { Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); Single<List<String>> single = w.toList(); SingleObserver<List<String>> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", "two", "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); }
@Test public void testListViaFlowable() { Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); Single<List<String>> single = w.toList(); SingleObserver<List<String>> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", "two", "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); }
@Test @Ignore("Null values are not allowed") public void testListWithNullValue() { Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", null, "three")); Single<List<String>> single = w.toList(); SingleObserver<List<String>> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", null, "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); }
@Override public Publisher<List<Integer>> createPublisher(final long elements) { return Flowable.range(1, 1000).toList().toFlowable() ; }
@Test(expected = NullPointerException.class) public void toListSupplierReturnsNullSingle() { just1.toList(new Callable<Collection<Integer>>() { @Override public Collection<Integer> call() { return null; } }).blockingGet(); }
@Test public void testToFutureList() throws InterruptedException, ExecutionException { Flowable<String> obs = Flowable.just("one", "two", "three"); Future<List<String>> f = obs.toList().toFuture(); assertEquals("one", f.get().get(0)); assertEquals("two", f.get().get(1)); assertEquals("three", f.get().get(2)); }
@Test @Ignore("Null values are not allowed") public void testListWithNullValueFlowable() { Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", null, "three")); Flowable<List<String>> flowable = w.toList().toFlowable(); Subscriber<List<String>> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); verify(subscriber, times(1)).onNext(Arrays.asList("one", null, "three")); verify(subscriber, Mockito.never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test public void startWithIterable() { List<String> li = new ArrayList<String>(); li.add("alpha"); li.add("beta"); List<String> values = Flowable.just("one", "two").startWith(li).toList().blockingGet(); assertEquals("alpha", values.get(0)); assertEquals("beta", values.get(1)); assertEquals("one", values.get(2)); assertEquals("two", values.get(3)); }
@Test public void testListWithBlockingFirst() { Flowable<String> f = Flowable.fromIterable(Arrays.asList("one", "two", "three")); List<String> actual = f.toList().blockingGet(); Assert.assertEquals(Arrays.asList("one", "two", "three"), actual); }
@Test public void testListWithBlockingFirstFlowable() { Flowable<String> f = Flowable.fromIterable(Arrays.asList("one", "two", "three")); List<String> actual = f.toList().toFlowable().blockingFirst(); Assert.assertEquals(Arrays.asList("one", "two", "three"), actual); }
@Test(expected = NullPointerException.class) public void toListSupplierReturnsNull() { just1.toList(new Callable<Collection<Integer>>() { @Override public Collection<Integer> call() { return null; } }).toFlowable().blockingSubscribe(); }
@SuppressWarnings("unchecked") @Test public void capacityHint() { Flowable.range(1, 10) .toList(4) .test() .assertResult(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); }
@Test public void startWith1() { List<String> values = Flowable.just("one", "two") .startWithArray("zero").toList().blockingGet(); assertEquals("zero", values.get(0)); assertEquals("two", values.get(2)); }
@Test public void testConcatSimple() { Flowable<String> f1 = Flowable.just("one", "two"); Flowable<String> f2 = Flowable.just("three", "four"); List<String> values = Flowable.concat(f1, f2).toList().blockingGet(); assertEquals("one", values.get(0)); assertEquals("two", values.get(1)); assertEquals("three", values.get(2)); assertEquals("four", values.get(3)); }
@Test public void testMergeCovariance3() { Flowable<Movie> f1 = Flowable.just(new HorrorMovie(), new Movie()); Flowable<Media> f2 = Flowable.just(new Media(), new HorrorMovie()); List<Media> values = Flowable.merge(f1, f2).toList().blockingGet(); assertTrue(values.get(0) instanceof HorrorMovie); assertTrue(values.get(1) instanceof Movie); assertTrue(values.get(2) != null); assertTrue(values.get(3) instanceof HorrorMovie); }
@Test(timeout = 2000) public void testRepeatTake() { Flowable<Integer> xs = Flowable.just(1, 2); Object[] ys = xs.repeat().subscribeOn(Schedulers.newThread()).take(4).toList().blockingGet().toArray(); assertArrayEquals(new Object[] { 1, 2, 1, 2 }, ys); }
@SuppressWarnings("unchecked") @Test public void error() { Flowable.error(new TestException()) .toList() .toFlowable() .test() .assertFailure(TestException.class); }
@Test public void testMergeCovariance() { Flowable<Media> f1 = Flowable.<Media> just(new HorrorMovie(), new Movie()); Flowable<Media> f2 = Flowable.just(new Media(), new HorrorMovie()); Flowable<Flowable<Media>> os = Flowable.just(f1, f2); List<Media> values = Flowable.merge(os).toList().blockingGet(); assertEquals(4, values.size()); }
@Test public void testMergeCovariance2() { Flowable<Media> f1 = Flowable.just(new HorrorMovie(), new Movie(), new Media()); Flowable<Media> f2 = Flowable.just(new Media(), new HorrorMovie()); Flowable<Flowable<Media>> os = Flowable.just(f1, f2); List<Media> values = Flowable.merge(os).toList().blockingGet(); assertEquals(5, values.size()); }