Search in sources :

Example 51 with Maybe

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

the class ObservableMergeWithMaybeTest method onErrorMainOverflow.

@Test
public void onErrorMainOverflow() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final AtomicReference<Observer<?>> observerRef = new AtomicReference<>();
        TestObserver<Integer> to = new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observerRef.set(observer);
            }
        }.mergeWith(Maybe.<Integer>error(new IOException())).test();
        observerRef.get().onError(new TestException());
        to.assertFailure(IOException.class);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Test(org.junit.Test)

Example 52 with Maybe

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

the class RxJavaPluginsTest method maybeCreate.

@SuppressWarnings("rawtypes")
@Test
public void maybeCreate() {
    try {
        RxJavaPlugins.setOnMaybeAssembly(new Function<Maybe, Maybe>() {

            @Override
            public Maybe apply(Maybe t) {
                return new MaybeError(new TestException());
            }
        });
        Maybe.empty().test().assertNoValues().assertNotComplete().assertError(TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
    // make sure the reset worked
    Maybe.empty().test().assertNoValues().assertNoErrors().assertComplete();
}
Also used : MaybeError(io.reactivex.rxjava3.internal.operators.maybe.MaybeError) Test(org.junit.Test)

Example 53 with Maybe

use of io.reactivex.rxjava3.core.Maybe 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 54 with Maybe

use of io.reactivex.rxjava3.core.Maybe 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 55 with Maybe

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

the class FlowableFirstTest method firstWithPredicateAndOneElement.

@Test
public void firstWithPredicateAndOneElement() {
    Maybe<Integer> maybe = Flowable.just(1, 2).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer t1) {
            return t1 % 2 == 0;
        }
    }).firstElement();
    maybe.subscribe(wm);
    InOrder inOrder = inOrder(wm);
    inOrder.verify(wm, times(1)).onSuccess(2);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Predicate(io.reactivex.rxjava3.functions.Predicate)

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