@Test public void testIsEmptyWithEmpty() { Flowable<Integer> w = Flowable.empty(); Single<Boolean> single = w.isEmpty(); SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); verify(observer, times(1)).onSuccess(true); verify(observer, never()).onSuccess(false); verify(observer, never()).onError(any(Throwable.class)); }
@Override public Publisher<Boolean> createPublisher(final long elements) { return Flowable.range(1, 10).isEmpty().toFlowable() ; }
@Test public void testIsEmptyWithOneItem() { Flowable<Integer> w = Flowable.just(1); Single<Boolean> single = w.isEmpty(); SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); verify(observer, never()).onSuccess(true); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onError(any(Throwable.class)); }
@Test public void testIsEmptyWithTwoItems() { Flowable<Integer> w = Flowable.just(1, 2); Single<Boolean> single = w.isEmpty(); SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); verify(observer, never()).onSuccess(true); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onError(any(Throwable.class)); }
@Test public void testIsEmptyWithOneItemFlowable() { Flowable<Integer> w = Flowable.just(1); Single<Boolean> single = w.isEmpty(); SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); verify(observer, never()).onSuccess(true); verify(observer, times(1)).onSuccess(false); verify(observer, never()).onError(any(Throwable.class)); }
@Test public void testIsEmptyWithTwoItemsFlowable() { Flowable<Integer> w = Flowable.just(1, 2); Flowable<Boolean> flowable = w.isEmpty().toFlowable(); Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); verify(subscriber, never()).onNext(true); verify(subscriber, times(1)).onNext(false); verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test public void testIsEmptyWithEmptyFlowable() { Flowable<Integer> w = Flowable.empty(); Flowable<Boolean> flowable = w.isEmpty().toFlowable(); Subscriber<Boolean> 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(timeout = 5000) public void testIssue1935NoUnsubscribeDownstream() { Flowable<Integer> source = Flowable.just(1).isEmpty() .flatMapPublisher(new Function<Boolean, Publisher<Integer>>() { @Override public Publisher<Integer> apply(Boolean t1) { return Flowable.just(2).delay(500, TimeUnit.MILLISECONDS); } }); assertEquals((Object)2, source.blockingFirst()); }
@Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstreamFlowable() { Flowable<Integer> source = Flowable.just(1).isEmpty() .flatMapPublisher(new Function<Boolean, Publisher<Integer>>() { @Override public Publisher<Integer> apply(Boolean t1) { return Flowable.just(2).delay(500, TimeUnit.MILLISECONDS); } }); assertEquals((Object)2, source.blockingFirst()); }
@Test public void testWithEmptyFlowable() { assertTrue(Flowable.empty().ignoreElements().toFlowable().isEmpty().blockingGet()); }
@Test public void testWithNonEmptyFlowable() { assertTrue(Flowable.just(1, 2, 3).ignoreElements().toFlowable().isEmpty().blockingGet()); }