Search in sources :

Example 1 with TestHelper

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

the class MaybeDoOnEventTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final 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);
            }
        }.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)

Example 2 with TestHelper

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

the class FlowableReplayEagerTruncateTest method badSource.

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

            @Override
            protected void subscribeActual(Subscriber<? super Integer> subscriber) {
                subscriber.onSubscribe(new BooleanSubscription());
                subscriber.onError(new TestException("First"));
                subscriber.onNext(1);
                subscriber.onError(new TestException("Second"));
                subscriber.onComplete();
            }
        }.replay().autoConnect().to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) ConnectableFlowable(io.reactivex.rxjava3.flowables.ConnectableFlowable)

Example 3 with TestHelper

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

the class FlowableMergeTest method mergeErrors.

@Test
public void mergeErrors() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable<Integer> source1 = Flowable.error(new TestException("First"));
        Flowable<Integer> source2 = Flowable.error(new TestException("Second"));
        Flowable.merge(source1, source2).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 4 with TestHelper

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

the class ObservableJoinTest method badEndSource.

@Test
public void badEndSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        @SuppressWarnings("rawtypes") final Observer[] o = { null };
        TestObserverEx<Integer> to = Observable.just(1).join(Observable.just(2), Functions.justFunction(Observable.never()), Functions.justFunction(new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                o[0] = observer;
                observer.onSubscribe(Disposable.empty());
                observer.onError(new TestException("First"));
            }
        }), new BiFunction<Integer, Integer, Integer>() {

            @Override
            public Integer apply(Integer a, Integer b) throws Exception {
                return a + b;
            }
        }).to(TestHelper.<Integer>testConsumer());
        o[0].onError(new TestException("Second"));
        to.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)

Example 5 with TestHelper

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

the class ObservableMergeTest method mergeErrors.

@Test
public void mergeErrors() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Observable<Integer> source1 = Observable.error(new TestException("First"));
        Observable<Integer> source2 = Observable.error(new TestException("Second"));
        Observable.merge(source1, source2).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

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