Search in sources :

Example 6 with Predicate

use of io.reactivex.functions.Predicate in project RxJava by ReactiveX.

the class ObservableFirstTest method testFirstWithPredicateAndEmpty.

@Test
public void testFirstWithPredicateAndEmpty() {
    Maybe<Integer> o = Observable.just(1).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer t1) {
            return t1 % 2 == 0;
        }
    }).firstElement();
    o.subscribe(wm);
    InOrder inOrder = inOrder(wm);
    inOrder.verify(wm, times(1)).onComplete();
    inOrder.verify(wm, never()).onError(any(Throwable.class));
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Predicate(io.reactivex.functions.Predicate)

Example 7 with Predicate

use of io.reactivex.functions.Predicate in project RxBus by ViTess.

the class BusProxy method createMethod.

protected <V> void createMethod(String tag, Scheduler scheduler, final Class<V> clazz, final IAction<T, V> proxyAction) {
    BusProcessor p = BusProcessor.create();
    BusSubscriber<V> busSubscriber = new BusSubscriber<>(new Consumer<V>() {

        @Override
        public void accept(V v) throws Exception {
            //TODO:thread-safe Entitys
            for (T t : Entitys) {
                proxyAction.toDo(t, v);
            }
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            Log.e("RxBus", throwable.getMessage());
        }
    }, Functions.EMPTY_ACTION, FlowableInternalHelper.RequestMax.INSTANCE);
    //no need filter,because RxJava2 unsupport null
    p.filter(new Predicate() {

        @Override
        public boolean test(Object o) throws Exception {
            return clazz.isInstance(o);
        }
    }).observeOn(scheduler).subscribeWith(busSubscriber);
    Set<BusProcessor<T>> bPros = SubjectMap.get(tag);
    if (bPros == null) {
        bPros = new HashSet<>();
        SubjectMap.put(tag, bPros);
    }
    bPros.add(p);
}
Also used : Predicate(io.reactivex.functions.Predicate)

Example 8 with Predicate

use of io.reactivex.functions.Predicate in project RxJava by ReactiveX.

the class FlowableFirstTest method testFirstWithPredicateAndEmpty.

@Test
public void testFirstWithPredicateAndEmpty() {
    Maybe<Integer> observable = Flowable.just(1).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer t1) {
            return t1 % 2 == 0;
        }
    }).firstElement();
    observable.subscribe(wm);
    InOrder inOrder = inOrder(wm);
    inOrder.verify(wm).onComplete();
    inOrder.verify(wm, never()).onError(any(Throwable.class));
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Predicate(io.reactivex.functions.Predicate)

Example 9 with Predicate

use of io.reactivex.functions.Predicate in project RxJava by ReactiveX.

the class FlowableFirstTest method testFirstWithPredicate.

@Test
public void testFirstWithPredicate() {
    Maybe<Integer> observable = Flowable.just(1, 2, 3, 4, 5, 6).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer t1) {
            return t1 % 2 == 0;
        }
    }).firstElement();
    observable.subscribe(wm);
    InOrder inOrder = inOrder(wm);
    inOrder.verify(wm, times(1)).onSuccess(2);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Predicate(io.reactivex.functions.Predicate)

Example 10 with Predicate

use of io.reactivex.functions.Predicate in project RxJava by ReactiveX.

the class ObservableFirstTest method testFirstOrDefaultWithPredicateAndOneElement.

@Test
public void testFirstOrDefaultWithPredicateAndOneElement() {
    Single<Integer> o = Observable.just(1, 2).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer t1) {
            return t1 % 2 == 0;
        }
    }).first(4);
    o.subscribe(wo);
    InOrder inOrder = inOrder(wo);
    inOrder.verify(wo, times(1)).onSuccess(2);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Predicate(io.reactivex.functions.Predicate)

Aggregations

Predicate (io.reactivex.functions.Predicate)13 InOrder (org.mockito.InOrder)12