OperationAny { public static <T> OnSubscribeFunc<Boolean> any(Observable<? extends T> source) { return new Any<T>(source, alwaysTrue(), false); }  static OnSubscribeFunc<Boolean> any(Observable<? extends T> source); static OnSubscribeFunc<Boolean> isEmpty(Observable<? extends T> source); static OnSubscribeFunc<Boolean> any(Observable<? extends T> source, Func1<? super T, Boolean> predicate); static OnSubscribeFunc<Boolean> exists(Observable<? extends T> source, Func1<? super T, Boolean> predicate);  }
@Test public void testAnyWithTwoItems() { Observable<Integer> w = Observable.from(1, 2); Observable<Boolean> observable = Observable.create(any(w)); @SuppressWarnings("unchecked") Observer<Boolean> observer = mock(Observer.class); observable.subscribe(observer); verify(observer, never()).onNext(false); verify(observer, times(1)).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onCompleted(); }
@Test public void testAnyWithOneItem() { Observable<Integer> w = Observable.from(1); Observable<Boolean> observable = Observable.create(any(w)); @SuppressWarnings("unchecked") Observer<Boolean> observer = mock(Observer.class); observable.subscribe(observer); verify(observer, never()).onNext(false); verify(observer, times(1)).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onCompleted(); }
@Test public void testAnyWithEmpty() { Observable<Integer> w = Observable.empty(); Observable<Boolean> observable = Observable.create(any(w)); @SuppressWarnings("unchecked") Observer<Boolean> observer = mock(Observer.class); observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onCompleted(); }
@Test public void testAnyWithPredicate1() { Observable<Integer> w = Observable.from(1, 2, 3); Observable<Boolean> observable = Observable.create(any(w, new Func1<Integer, Boolean>() { @Override public Boolean call(Integer t1) { return t1 < 2; } })); @SuppressWarnings("unchecked") Observer<Boolean> observer = mock(Observer.class); observable.subscribe(observer); verify(observer, never()).onNext(false); verify(observer, times(1)).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onCompleted(); }
@Test public void testAnyWithPredicate2() { Observable<Integer> w = Observable.from(1, 2, 3); Observable<Boolean> observable = Observable.create(any(w, new Func1<Integer, Boolean>() { @Override public Boolean call(Integer t1) { return t1 < 1; } })); @SuppressWarnings("unchecked") Observer<Boolean> observer = mock(Observer.class); observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onCompleted(); }
@Test public void testAnyWithEmptyAndPredicate() { Observable<Integer> w = Observable.empty(); Observable<Boolean> observable = Observable.create(any(w, new Func1<Integer, Boolean>() { @Override public Boolean call(Integer t1) { return true; } })); @SuppressWarnings("unchecked") Observer<Boolean> observer = mock(Observer.class); observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onCompleted(); }