@Test(expected = NullPointerException.class) public void firstNull() { just1.first(null); }
@Test public void testFirstOrElseOfNone() { Flowable<String> src = Flowable.empty(); src.first("default").subscribe(wo); verify(wo, times(1)).onSuccess(anyString()); verify(wo, times(1)).onSuccess("default"); verify(wo, never()).onError(any(Throwable.class)); }
@Test public void testFirstOrElseOfSome() { Flowable<String> src = Flowable.just("a", "b", "c"); src.first("default").subscribe(wo); verify(wo, times(1)).onSuccess(anyString()); verify(wo, times(1)).onSuccess("a"); verify(wo, never()).onError(any(Throwable.class)); }
@Test public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() { Flowable<String> src = Flowable.just("a", "b", "c"); src.filter(IS_D).first("default").subscribe(wo); verify(wo, times(1)).onSuccess(anyString()); verify(wo, times(1)).onSuccess("default"); verify(wo, never()).onError(any(Throwable.class)); }
@Test public void testFirstOrElseWithPredicateOfSome() { Flowable<String> src = Flowable.just("a", "b", "c", "d", "e", "f"); src.filter(IS_D).first("default").subscribe(wo); verify(wo, times(1)).onSuccess(anyString()); verify(wo, times(1)).onSuccess("d"); verify(wo, never()).onError(any(Throwable.class)); }
@Test public void testFirstOrDefaultWithEmpty() { Single<Integer> single = Flowable.<Integer> empty() .first(1); single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(1); inOrder.verifyNoMoreInteractions(); }
@Test public void testFirstOrDefault() { Single<Integer> single = Flowable.just(1, 2, 3) .first(4); single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(1); inOrder.verifyNoMoreInteractions(); }
@Test public void testFirstOrDefaultWithOneElement() { Single<Integer> single = Flowable.just(1).first(2); single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(1); inOrder.verifyNoMoreInteractions(); }
@Test public void testFirstOrElseOfSomeFlowable() { Flowable<String> src = Flowable.just("a", "b", "c"); src.first("default").toFlowable().subscribe(w); verify(w, times(1)).onNext(anyString()); verify(w, times(1)).onNext("a"); verify(w, never()).onError(any(Throwable.class)); verify(w, times(1)).onComplete(); }
@Test public void testFirstOrElseOfNoneFlowable() { Flowable<String> src = Flowable.empty(); src.first("default").toFlowable().subscribe(w); verify(w, times(1)).onNext(anyString()); verify(w, times(1)).onNext("default"); verify(w, never()).onError(any(Throwable.class)); verify(w, times(1)).onComplete(); }
@Test public void testFirstOrElseWithPredicateOfSomeFlowable() { Flowable<String> src = Flowable.just("a", "b", "c", "d", "e", "f"); src.filter(IS_D).first("default").toFlowable().subscribe(w); verify(w, times(1)).onNext(anyString()); verify(w, times(1)).onNext("d"); verify(w, never()).onError(any(Throwable.class)); verify(w, times(1)).onComplete(); }
@Test public void testFirstOrElseWithPredicateOfNoneMatchingThePredicateFlowable() { Flowable<String> src = Flowable.just("a", "b", "c"); src.filter(IS_D).first("default").toFlowable().subscribe(w); verify(w, times(1)).onNext(anyString()); verify(w, times(1)).onNext("default"); verify(w, never()).onError(any(Throwable.class)); verify(w, times(1)).onComplete(); }
@Test public void testFirstOrDefaultWithPredicate() { Single<Integer> single = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate<Integer>() { @Override public boolean test(Integer t1) { return t1 % 2 == 0; } }) .first(8); single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(2); inOrder.verifyNoMoreInteractions(); }
@Test public void testFirstOrDefaultWithPredicateAndEmpty() { Single<Integer> single = Flowable.just(1) .filter(new Predicate<Integer>() { @Override public boolean test(Integer t1) { return t1 % 2 == 0; } }) .first(2); single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(2); inOrder.verifyNoMoreInteractions(); }
@Test public void testFirstOrDefaultWithPredicateAndOneElement() { Single<Integer> single = Flowable.just(1, 2) .filter(new Predicate<Integer>() { @Override public boolean test(Integer t1) { return t1 % 2 == 0; } }) .first(4); single.subscribe(wo); InOrder inOrder = inOrder(wo); inOrder.verify(wo, times(1)).onSuccess(2); inOrder.verifyNoMoreInteractions(); }
@Test public void testFirstOrDefaultWithEmptyFlowable() { Flowable<Integer> flowable = Flowable.<Integer> empty() .first(1).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(); }
@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(); }
@Test public void testFirstOrDefaultWithOneElementFlowable() { Flowable<Integer> flowable = Flowable.just(1).first(2).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(); }
@Test public void testFirstOrDefaultWithPredicateAndEmptyFlowable() { Flowable<Integer> flowable = Flowable.just(1) .filter(new Predicate<Integer>() { @Override public boolean test(Integer t1) { return t1 % 2 == 0; } }) .first(2).toFlowable(); Subscriber<Integer> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); InOrder inOrder = inOrder(subscriber); inOrder.verify(subscriber, times(1)).onNext(2); inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }
@Test public void testFirstOrDefaultWithPredicateAndOneElementFlowable() { Flowable<Integer> flowable = Flowable.just(1, 2) .filter(new Predicate<Integer>() { @Override public boolean test(Integer t1) { return t1 % 2 == 0; } }) .first(4).toFlowable(); Subscriber<Integer> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); InOrder inOrder = inOrder(subscriber); inOrder.verify(subscriber, times(1)).onNext(2); inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }