@Override public Flowable<Object> apply(Flowable<Object> f) throws Exception { return f.last(2).toFlowable(); } });
@Override public Flowable<List<Object>> apply(Flowable<Object> f) throws Exception { return f.toList().toFlowable(); } });
@Override public Object apply(Flowable<Object> f) throws Exception { return f.singleOrError().toFlowable(); } }, false, 1, 1, 1);
@Override public Publisher<Boolean> createPublisher(final long elements) { return Flowable.range(1, 1000).all(new Predicate<Integer>() { @Override public boolean test(Integer e) throws Exception { return e < 800; } }).toFlowable() ; }
@Override public Publisher<Boolean> apply(Flowable<Object> f) throws Exception { return f.any(Functions.alwaysTrue()).toFlowable(); } });
@Test @Ignore("null values are not allowed") public void testContainsWithNullFlowable() { Flowable<Boolean> flowable = Flowable.just("a", "b", null).contains(null).toFlowable(); Subscriber<Object> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); verify(subscriber, times(1)).onNext(true); verify(subscriber, never()).onNext(false); verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test public void testFirstOrDefaultFlowable() { Flowable<Integer> flowable = Flowable.just(1, 2, 3) .first(4).toFlowable(); Subscriber<Integer> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); InOrder inOrder = inOrder(subscriber); inOrder.verify(subscriber, times(1)).onNext(1); inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }
@Override public Publisher<Boolean> createPublisher(final long elements) { return Flowable.sequenceEqual( Flowable.range(1, 1000), Flowable.range(1, 1001)) .toFlowable() ; }
@Test public void testSingleOrDefaultWithTooManyElementsFlowable() { Flowable<Integer> flowable = Flowable.just(1, 2).single(3).toFlowable(); Subscriber<Integer> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); InOrder inOrder = inOrder(subscriber); inOrder.verify(subscriber, times(1)).onError( isA(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); }
@Test public void test1Flowable() { Flowable<Boolean> flowable = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable.just("one", "two", "three")).toFlowable(); verifyResult(flowable, true); }
@Test public void testWithEmpty2Flowable() { Flowable<Boolean> flowable = Flowable.sequenceEqual( Flowable.just("one", "two", "three"), Flowable.<String> empty()).toFlowable(); verifyResult(flowable, false); }
@Test public void testWithEqualityErrorFlowable() { Flowable<Boolean> flowable = Flowable.sequenceEqual( Flowable.just("one"), Flowable.just("one"), new BiPredicate<String, String>() { @Override public boolean test(String t1, String t2) { throw new TestException(); } }).toFlowable(); verifyError(flowable); }
@Test public void singleOrError() { Flowable.empty() .singleOrError() .toFlowable() .test() .assertFailure(NoSuchElementException.class); } }
@Test public void firstOrErrorOneElementFlowable() { Flowable.just(1) .firstOrError() .toFlowable() .test() .assertNoErrors() .assertValue(1); }
@Test public void testJustTwoEmissionsObservableThrowsError() { TestSubscriber<String> subscriber = TestSubscriber.create(); Single<String> single = Flowable.just("First", "Second").single(""); single.toFlowable().subscribe(subscriber); subscriber.assertError(IllegalArgumentException.class); }
@Test public void testEmptyObservable() { TestSubscriber<String> subscriber = TestSubscriber.create(); Single<String> single = Flowable.<String>empty().single(""); single.toFlowable().subscribe(subscriber); subscriber.assertResult(""); }
@Test public void prefetchFlowable() { Flowable.sequenceEqual(Flowable.range(1, 20), Flowable.range(1, 20), 2) .toFlowable() .test() .assertResult(true); }
@Test public void dispose() { TestHelper.checkDisposed(Flowable.just(1).count()); TestHelper.checkDisposed(Flowable.just(1).count().toFlowable()); }
@Test public void andThenSingleNever() { TestSubscriber<String> ts = new TestSubscriber<String>(0); Completable.never().andThen(Single.just("foo")).toFlowable().subscribe(ts); ts.request(1); ts.assertNoValues(); ts.assertNotTerminated(); }
@Test public void cancelAsFlowable() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = pp.singleOrError().toFlowable().test(); assertTrue(pp.hasSubscribers()); ts.assertEmpty(); ts.cancel(); assertFalse(pp.hasSubscribers()); }