Search in sources :

Example 46 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class XFlatMapTest method observerMaybe.

@Test
public void observerMaybe() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Observable.just(1).subscribeOn(Schedulers.io()).flatMapMaybe(new Function<Integer, Maybe<Integer>>() {

            @Override
            public Maybe<Integer> apply(Integer v) throws Exception {
                sleep();
                return Maybe.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 47 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class XFlatMapTest method singleMaybe.

@Test
public void singleMaybe() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Single.just(1).subscribeOn(Schedulers.io()).flatMapMaybe(new Function<Integer, Maybe<Integer>>() {

            @Override
            public Maybe<Integer> apply(Integer v) throws Exception {
                sleep();
                return Maybe.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 48 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class XFlatMapTest method flowableMaybe.

@Test
public void flowableMaybe() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestSubscriber<Integer> ts = Flowable.just(1).subscribeOn(Schedulers.io()).flatMapMaybe(new Function<Integer, Maybe<Integer>>() {

            @Override
            public Maybe<Integer> apply(Integer v) throws Exception {
                sleep();
                return Maybe.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(ts);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 49 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class ConverterTest method maybeConverterThrows.

@Test
public void maybeConverterThrows() {
    try {
        Maybe.just(1).to(new MaybeConverter<Integer, Integer>() {

            @Override
            public Integer apply(Maybe<Integer> v) {
                throw new TestException("Forced failure");
            }
        });
        fail("Should have thrown!");
    } catch (TestException ex) {
        assertEquals("Forced failure", ex.getMessage());
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 50 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class FlowableMergeWithMaybeTest method onErrorMainOverflow.

@Test
public void onErrorMainOverflow() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final AtomicReference<Subscriber<?>> subscriber = new AtomicReference<>();
        TestSubscriber<Integer> ts = new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                subscriber.set(s);
            }
        }.mergeWith(Maybe.<Integer>error(new IOException())).test();
        subscriber.get().onError(new TestException());
        ts.assertFailure(IOException.class);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)55 TestException (io.reactivex.rxjava3.exceptions.TestException)38 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 Maybe (io.reactivex.rxjava3.core.Maybe)12 InOrder (org.mockito.InOrder)12 Flowable (io.reactivex.rxjava3.core.Flowable)10 Observable (io.reactivex.rxjava3.core.Observable)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 Single (io.reactivex.rxjava3.core.Single)8 IOException (java.io.IOException)8 Predicate (io.reactivex.rxjava3.functions.Predicate)6 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Type (java.lang.reflect.Type)6 Test (org.junit.jupiter.api.Test)6 TestObserver (io.reactivex.rxjava3.observers.TestObserver)5 Completable (io.reactivex.rxjava3.core.Completable)4 Action (io.reactivex.rxjava3.functions.Action)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 FlowableRxInvoker (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker)4 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider)4