Search in sources :

Example 26 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class ObservableReplayTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onError(new TestException("First"));
                observer.onNext(1);
                observer.onError(new TestException("Second"));
                observer.onComplete();
            }
        }.replay().autoConnect().to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Observer(io.reactivex.rxjava3.core.Observer) Observable(io.reactivex.rxjava3.core.Observable) ConnectableObservable(io.reactivex.rxjava3.observables.ConnectableObservable)

Example 27 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class CompletableMergeTest method mainErrorInnerErrorDelayedRace.

@Test
public void mainErrorInnerErrorDelayedRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final PublishProcessor<Integer> pp1 = PublishProcessor.create();
        final PublishProcessor<Integer> pp2 = PublishProcessor.create();
        TestObserverEx<Void> to = Completable.mergeDelayError(pp1.map(new Function<Integer, Completable>() {

            @Override
            public Completable apply(Integer v) throws Exception {
                return pp2.ignoreElements();
            }
        })).to(TestHelper.<Void>testConsumer());
        pp1.onNext(1);
        final Throwable ex1 = new TestException();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                pp1.onError(ex1);
            }
        };
        final Throwable ex2 = new TestException();
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                pp2.onError(ex2);
            }
        };
        TestHelper.race(r1, r2);
        to.assertFailure(CompositeException.class);
        List<Throwable> errors = TestHelper.compositeList(to.errors().get(0));
        TestHelper.assertError(errors, 0, TestException.class);
        TestHelper.assertError(errors, 1, TestException.class);
    }
}
Also used : AtomicThrowable(io.reactivex.rxjava3.internal.util.AtomicThrowable) Test(org.junit.Test)

Example 28 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class MaybeDoOnTerminateTest method doOnTerminateErrorCrash.

@Test
public void doOnTerminateErrorCrash() {
    TestObserverEx<Object> to = Maybe.error(new TestException("Outer")).doOnTerminate(new Action() {

        @Override
        public void run() {
            throw new TestException("Inner");
        }
    }).to(TestHelper.<Object>testConsumer()).assertFailure(CompositeException.class);
    List<Throwable> errors = TestHelper.compositeList(to.errors().get(0));
    TestHelper.assertError(errors, 0, TestException.class, "Outer");
    TestHelper.assertError(errors, 1, TestException.class, "Inner");
}
Also used : Action(io.reactivex.rxjava3.functions.Action) Test(org.junit.Test)

Example 29 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class MaybeDoOnLifecycleTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
        Action onDispose = mock(Action.class);
        doThrow(new TestException("First")).when(onSubscribe).accept(any());
        Disposable bs = Disposable.empty();
        new Maybe<Integer>() {

            @Override
            protected void subscribeActual(MaybeObserver<? super Integer> observer) {
                observer.onSubscribe(bs);
                observer.onError(new TestException("Second"));
                observer.onComplete();
                observer.onSuccess(1);
            }
        }.doOnLifecycle(onSubscribe, onDispose).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        assertTrue(bs.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
        verify(onSubscribe).accept(any());
        verify(onDispose, never()).run();
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 30 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class ObservableDoOnSubscribeTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final Disposable bs = Disposable.empty();
        new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(bs);
                observer.onError(new TestException("Second"));
                observer.onComplete();
            }
        }.doOnSubscribe(new Consumer<Disposable>() {

            @Override
            public void accept(Disposable d) throws Exception {
                throw new TestException("First");
            }
        }).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        assertTrue(bs.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 TestException (io.reactivex.rxjava3.exceptions.TestException)19 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)9 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)3 ConnectableFlowable (io.reactivex.rxjava3.flowables.ConnectableFlowable)3 TestObserver (io.reactivex.rxjava3.observers.TestObserver)3 Observable (io.reactivex.rxjava3.core.Observable)2 Observer (io.reactivex.rxjava3.core.Observer)2 AtomicThrowable (io.reactivex.rxjava3.internal.util.AtomicThrowable)2 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)2 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Action (io.reactivex.rxjava3.functions.Action)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Subscriber (org.reactivestreams.Subscriber)1