Search in sources :

Example 86 with Action

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

the class FlowableConcatWithMaybeTest method normalEmpty.

@Test
public void normalEmpty() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    Flowable.range(1, 5).concatWith(Maybe.<Integer>fromAction(new Action() {

        @Override
        public void run() throws Exception {
            ts.onNext(100);
        }
    })).subscribe(ts);
    ts.assertResult(1, 2, 3, 4, 5, 100);
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 87 with Action

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

the class FlowableConcatWithMaybeTest method mainError.

@Test
public void mainError() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    Flowable.<Integer>error(new TestException()).concatWith(Maybe.<Integer>fromAction(new Action() {

        @Override
        public void run() throws Exception {
            ts.onNext(100);
        }
    })).subscribe(ts);
    ts.assertFailure(TestException.class);
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 88 with Action

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

the class FlowableDoOnEachTest method onErrorAfterCrash.

@Test
public void onErrorAfterCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.fromPublisher(new Publisher<Object>() {

            @Override
            public void subscribe(Subscriber<? super Object> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onError(new TestException());
            }
        }).doAfterTerminate(new Action() {

            @Override
            public void run() throws Exception {
                throw new IOException();
            }
        }).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) ConditionalSubscriber(io.reactivex.rxjava3.operators.ConditionalSubscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) IOException(java.io.IOException) IOException(java.io.IOException)

Example 89 with Action

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

the class FlowableDoOnEachTest method onCompleteAfterCrash.

@Test
public void onCompleteAfterCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.fromPublisher(new Publisher<Object>() {

            @Override
            public void subscribe(Subscriber<? super Object> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onComplete();
            }
        }).doAfterTerminate(new Action() {

            @Override
            public void run() throws Exception {
                throw new IOException();
            }
        }).test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) ConditionalSubscriber(io.reactivex.rxjava3.operators.ConditionalSubscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) IOException(java.io.IOException) IOException(java.io.IOException)

Example 90 with Action

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

the class FlowableDoOnEachTest method onCompleteCrash.

@Test
public void onCompleteCrash() {
    Flowable.fromPublisher(new Publisher<Object>() {

        @Override
        public void subscribe(Subscriber<? super Object> s) {
            s.onSubscribe(new BooleanSubscription());
            s.onComplete();
        }
    }).doOnComplete(new Action() {

        @Override
        public void run() throws Exception {
            throw new IOException();
        }
    }).test().assertFailure(IOException.class);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) ConditionalSubscriber(io.reactivex.rxjava3.operators.ConditionalSubscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

Test (org.junit.Test)109 TestException (io.reactivex.rxjava3.exceptions.TestException)64 Action (io.reactivex.rxjava3.functions.Action)49 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)13 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 TestObserver (io.reactivex.rxjava3.observers.TestObserver)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)9 IOException (java.io.IOException)9 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 Observable (io.reactivex.rxjava3.core.Observable)4 ForEachWhileSubscriber (io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber)4 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)3 Flowable (io.reactivex.rxjava3.core.Flowable)3 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)3 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3