Search in sources :

Example 6 with Maybe

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

the class MaybeBlockingSubscribeTest method threeArgEmptyFails.

@Test
public void threeArgEmptyFails() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<Integer> success = mock(Consumer.class);
        @SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
        Action action = mock(Action.class);
        doThrow(new TestException()).when(action).run();
        Maybe.<Integer>empty().delay(50, TimeUnit.MILLISECONDS, Schedulers.computation()).blockingSubscribe(success, consumer, action);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        verify(success, never()).accept(any());
        verify(consumer, never()).accept(any());
        verify(action).run();
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 7 with Maybe

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

the class MaybeBlockingSubscribeTest method twoArgErrorFails.

@Test
public void twoArgErrorFails() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<Integer> success = mock(Consumer.class);
        @SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
        doThrow(new TestException()).when(consumer).accept(any());
        Maybe.<Integer>error(new TestException()).delay(50, TimeUnit.MILLISECONDS, Schedulers.computation()).blockingSubscribe(success, consumer);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        verify(success, never()).accept(any());
        verify(consumer).accept(any(TestException.class));
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 8 with Maybe

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

the class RxJavaPluginsTest method clearIsPassthrough.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void clearIsPassthrough() {
    try {
        RxJavaPlugins.reset();
        assertNull(RxJavaPlugins.onAssembly((Observable) null));
        assertNull(RxJavaPlugins.onAssembly((ConnectableObservable) null));
        assertNull(RxJavaPlugins.onAssembly((Flowable) null));
        assertNull(RxJavaPlugins.onAssembly((ConnectableFlowable) null));
        Observable oos = new Observable() {

            @Override
            public void subscribeActual(Observer t) {
            }
        };
        Flowable fos = new Flowable() {

            @Override
            public void subscribeActual(Subscriber t) {
            }
        };
        assertSame(oos, RxJavaPlugins.onAssembly(oos));
        assertSame(fos, RxJavaPlugins.onAssembly(fos));
        assertNull(RxJavaPlugins.onAssembly((Single) null));
        Single sos = new Single() {

            @Override
            public void subscribeActual(SingleObserver t) {
            }
        };
        assertSame(sos, RxJavaPlugins.onAssembly(sos));
        assertNull(RxJavaPlugins.onAssembly((Completable) null));
        Completable cos = new Completable() {

            @Override
            public void subscribeActual(CompletableObserver t) {
            }
        };
        assertSame(cos, RxJavaPlugins.onAssembly(cos));
        assertNull(RxJavaPlugins.onAssembly((Maybe) null));
        Maybe myb = new Maybe() {

            @Override
            public void subscribeActual(MaybeObserver t) {
            }
        };
        assertSame(myb, RxJavaPlugins.onAssembly(myb));
        Runnable action = Functions.EMPTY_RUNNABLE;
        assertSame(action, RxJavaPlugins.onSchedule(action));
        class AllSubscriber implements Subscriber, Observer, SingleObserver, CompletableObserver, MaybeObserver {

            @Override
            public void onSuccess(Object value) {
            }

            @Override
            public void onSubscribe(Disposable d) {
            }

            @Override
            public void onSubscribe(Subscription s) {
            }

            @Override
            public void onNext(Object t) {
            }

            @Override
            public void onError(Throwable t) {
            }

            @Override
            public void onComplete() {
            }
        }
        AllSubscriber all = new AllSubscriber();
        Subscriber[] allArray = { all };
        assertNull(RxJavaPlugins.onSubscribe(Observable.never(), null));
        assertSame(all, RxJavaPlugins.onSubscribe(Observable.never(), all));
        assertNull(RxJavaPlugins.onSubscribe(Flowable.never(), null));
        assertSame(all, RxJavaPlugins.onSubscribe(Flowable.never(), all));
        assertNull(RxJavaPlugins.onSubscribe(Single.just(1), null));
        assertSame(all, RxJavaPlugins.onSubscribe(Single.just(1), all));
        assertNull(RxJavaPlugins.onSubscribe(Completable.never(), null));
        assertSame(all, RxJavaPlugins.onSubscribe(Completable.never(), all));
        assertNull(RxJavaPlugins.onSubscribe(Maybe.never(), null));
        assertSame(all, RxJavaPlugins.onSubscribe(Maybe.never(), all));
        assertNull(RxJavaPlugins.onSubscribe(Flowable.never().parallel(), null));
        assertSame(allArray, RxJavaPlugins.onSubscribe(Flowable.never().parallel(), allArray));
        final Scheduler s = ImmediateThinScheduler.INSTANCE;
        Supplier<Scheduler> c = new Supplier<Scheduler>() {

            @Override
            public Scheduler get() throws Exception {
                return s;
            }
        };
        assertSame(s, RxJavaPlugins.onComputationScheduler(s));
        assertSame(s, RxJavaPlugins.onIoScheduler(s));
        assertSame(s, RxJavaPlugins.onNewThreadScheduler(s));
        assertSame(s, RxJavaPlugins.onSingleScheduler(s));
        assertSame(s, RxJavaPlugins.initComputationScheduler(c));
        assertSame(s, RxJavaPlugins.initIoScheduler(c));
        assertSame(s, RxJavaPlugins.initNewThreadScheduler(c));
        assertSame(s, RxJavaPlugins.initSingleScheduler(c));
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : ImmediateThinScheduler(io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler) ConnectableFlowable(io.reactivex.rxjava3.flowables.ConnectableFlowable) Observable(io.reactivex.rxjava3.core.Observable) ConnectableObservable(io.reactivex.rxjava3.observables.ConnectableObservable) Observer(io.reactivex.rxjava3.core.Observer) ConnectableObservable(io.reactivex.rxjava3.observables.ConnectableObservable) ScalarSubscription(io.reactivex.rxjava3.internal.subscriptions.ScalarSubscription) ParallelFlowable(io.reactivex.rxjava3.parallel.ParallelFlowable) ConnectableFlowable(io.reactivex.rxjava3.flowables.ConnectableFlowable) Test(org.junit.Test)

Example 9 with Maybe

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

the class ObservableConcatWithMaybeTest method normalEmpty.

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

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

Example 10 with Maybe

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

the class ObservableConcatWithMaybeTest method otherError.

@Test
public void otherError() {
    final TestObserver<Integer> to = new TestObserver<>();
    Observable.range(1, 5).concatWith(Maybe.<Integer>error(new TestException())).subscribe(to);
    to.assertFailure(TestException.class, 1, 2, 3, 4, 5);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) 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