Search in sources :

Example 31 with Predicate

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

the class ObservableTakeUntilPredicateTest method sourceThrows.

@Test
public void sourceThrows() {
    Observer<Object> o = TestHelper.mockObserver();
    Observable.just(1).concatWith(Observable.<Integer>error(new TestException())).concatWith(Observable.just(2)).takeUntil(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) {
            return false;
        }
    }).subscribe(o);
    verify(o).onNext(1);
    verify(o, never()).onNext(2);
    verify(o).onError(any(TestException.class));
    verify(o, never()).onComplete();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 32 with Predicate

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

the class FlowableRetryPredicate method subscribeActual.

@Override
public void subscribeActual(Subscriber<? super T> s) {
    SubscriptionArbiter sa = new SubscriptionArbiter(false);
    s.onSubscribe(sa);
    RetrySubscriber<T> rs = new RetrySubscriber<>(s, count, predicate, sa, source);
    rs.subscribeNext();
}
Also used : SubscriptionArbiter(io.reactivex.rxjava3.internal.subscriptions.SubscriptionArbiter)

Example 33 with Predicate

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

the class ObservableRetryBiPredicate method subscribeActual.

@Override
public void subscribeActual(Observer<? super T> observer) {
    SequentialDisposable sa = new SequentialDisposable();
    observer.onSubscribe(sa);
    RetryBiObserver<T> rs = new RetryBiObserver<>(observer, predicate, sa, source);
    rs.subscribeNext();
}
Also used : SequentialDisposable(io.reactivex.rxjava3.internal.disposables.SequentialDisposable)

Example 34 with Predicate

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

the class FlowableTakeUntilPredicateTest method errorIncludesLastValueAsCause.

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

        @Override
        public boolean test(String t) {
            throw e;
        }
    };
    Flowable.just("abc").takeUntil(predicate).subscribe(ts);
    ts.assertTerminated();
    ts.assertNotComplete();
    ts.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)

Example 35 with Predicate

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

the class FlowableTakeWhileTest method unsubscribeAfterTake.

@Test
public void unsubscribeAfterTake() {
    Subscription s = mock(Subscription.class);
    TestFlowable w = new TestFlowable(s, "one", "two", "three");
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    Flowable<String> take = Flowable.unsafeCreate(w).takeWhile(new Predicate<String>() {

        int index;

        @Override
        public boolean test(String s) {
            return index++ < 1;
        }
    });
    take.subscribe(subscriber);
    // wait for the Flowable to complete
    try {
        w.t.join();
    } catch (Throwable e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    System.out.println("TestFlowable thread finished");
    verify(subscriber, times(1)).onNext("one");
    verify(subscriber, never()).onNext("two");
    verify(subscriber, never()).onNext("three");
    verify(s, times(1)).cancel();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

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