Search in sources :

Example 16 with TestHelper

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

the class FlowablePublishTest method doubleErrorRefCount.

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

            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onError(new TestException("one"));
                s.onError(new TestException("two"));
            }
        }.publish(1).refCount().to(TestHelper.<Integer>testSubscriber(0L)).assertFailureAndMessage(TestException.class, "one");
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "two");
        assertEquals(1, errors.size());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) ConnectableFlowable(io.reactivex.rxjava3.flowables.ConnectableFlowable) Test(org.junit.Test)

Example 17 with TestHelper

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

the class FlowableReplayTest 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 18 with TestHelper

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

the class SingleMergeTest method mergeErrors.

@Test
public void mergeErrors() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Single<Integer> source1 = Single.error(new TestException("First"));
        Single<Integer> source2 = Single.error(new TestException("Second"));
        Single.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) Test(org.junit.Test)

Example 19 with TestHelper

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

the class SingleDoOnLifecycleTest 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 Single<Integer>() {

            @Override
            protected void subscribeActual(SingleObserver<? super Integer> observer) {
                observer.onSubscribe(bs);
                observer.onError(new TestException("Second"));
                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 20 with TestHelper

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

the class SingleFlatMapTest method flatMapPublisherCancelDuringSingle.

@Test
public void flatMapPublisherCancelDuringSingle() {
    final AtomicBoolean disposed = new AtomicBoolean();
    TestSubscriberEx<Integer> ts = Single.<Integer>never().doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            disposed.set(true);
        }
    }).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

        @Override
        public Publisher<Integer> apply(Integer v) throws Exception {
            return Flowable.range(v, 5);
        }
    }).to(TestHelper.<Integer>testConsumer()).assertNoValues().assertNotTerminated();
    assertFalse(disposed.get());
    ts.cancel();
    assertTrue(disposed.get());
    ts.assertNotTerminated();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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