Search in sources :

Example 46 with Predicate

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

the class FlowableFirstTest method firstOrDefaultWithPredicate.

@Test
public void firstOrDefaultWithPredicate() {
    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();
}
Also used : InOrder(org.mockito.InOrder) Predicate(io.reactivex.rxjava3.functions.Predicate)

Example 47 with Predicate

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

the class FlowableFirstTest method firstOrDefaultWithPredicateAndOneElement.

@Test
public void firstOrDefaultWithPredicateAndOneElement() {
    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();
}
Also used : InOrder(org.mockito.InOrder) Predicate(io.reactivex.rxjava3.functions.Predicate)

Example 48 with Predicate

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

the class FlowableConcatMapCompletableTest method immediateOuterInnerErrorRace.

@Test
public void immediateOuterInnerErrorRace() {
    final TestException ex = new TestException();
    for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp = PublishProcessor.create();
            final CompletableSubject cs = CompletableSubject.create();
            TestObserver<Void> to = pp.concatMapCompletable(Functions.justFunction(cs)).test();
            pp.onNext(1);
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    cs.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            to.assertError(new Predicate<Throwable>() {

                @Override
                public boolean test(Throwable e) throws Exception {
                    return e instanceof TestException || e instanceof CompositeException;
                }
            }).assertNotComplete();
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) Test(org.junit.Test)

Example 49 with Predicate

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

the class ObservableAnyTest method predicateThrowsSuppressOthers.

@Test
public void predicateThrowsSuppressOthers() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onNext(1);
                observer.onNext(2);
                observer.onError(new IOException());
                observer.onComplete();
            }
        }.any(new Predicate<Integer>() {

            @Override
            public boolean test(Integer v) throws Exception {
                throw new TestException();
            }
        }).toObservable().test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 50 with Predicate

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

the class ObservableTakeUntilPredicateTest method errorIncludesLastValueAsCause.

@Test
public void errorIncludesLastValueAsCause() {
    TestObserverEx<String> to = new TestObserverEx<>();
    final TestException e = new TestException("Forced failure");
    Predicate<String> predicate = (new Predicate<String>() {

        @Override
        public boolean test(String t) {
            throw e;
        }
    });
    Observable.just("abc").takeUntil(predicate).subscribe(to);
    to.assertTerminated();
    to.assertNotComplete();
    to.assertError(TestException.class);
// FIXME last cause value is not saved
// assertTrue(ts.errors().get(0).getCause().getMessage().contains("abc"));
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)31 TestException (io.reactivex.rxjava3.exceptions.TestException)25 Predicate (io.reactivex.rxjava3.functions.Predicate)12 InOrder (org.mockito.InOrder)12 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)11 IOException (java.io.IOException)9 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ForEachWhileSubscriber (io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber)5 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)3 Observable (io.reactivex.rxjava3.core.Observable)2 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)2 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)2 SubscriptionArbiter (io.reactivex.rxjava3.internal.subscriptions.SubscriptionArbiter)2 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)2 Callable (java.util.concurrent.Callable)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Flowable (io.reactivex.rxjava3.core.Flowable)1 Disposable (io.reactivex.rxjava3.disposables.Disposable)1 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)1