Search in sources :

Example 61 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class SingleSafeSubscribeTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
        doThrow(new TestException()).when(consumer).onSubscribe(any());
        Disposable d = Disposable.empty();
        new Single<Integer>() {

            @Override
            protected void subscribeActual(@NonNull SingleObserver<? super Integer> observer) {
                observer.onSubscribe(d);
                // none of the following should arrive at the consumer
                observer.onSuccess(1);
                observer.onError(new IOException());
            }
        }.safeSubscribe(consumer);
        InOrder order = inOrder(consumer);
        order.verify(consumer).onSubscribe(any(Disposable.class));
        order.verifyNoMoreInteractions();
        assertTrue(d.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        TestHelper.assertUndeliverable(errors, 1, IOException.class);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) IOException(java.io.IOException) Test(org.junit.Test)

Example 62 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class SingleTakeUntilTest method mainErrorSingle.

@Test
public void mainErrorSingle() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    PublishProcessor<Integer> source = PublishProcessor.create();
    TestObserver<Integer> to = source.single(-99).takeUntil(pp.single(-99)).test();
    source.onError(new TestException());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 63 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class SingleTakeUntilTest method mainErrorPublisher.

@Test
public void mainErrorPublisher() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    PublishProcessor<Integer> source = PublishProcessor.create();
    TestObserver<Integer> to = source.single(-99).takeUntil(pp).test();
    source.onError(new TestException());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 64 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class SingleTakeUntilTest method mainErrorCompletable.

@Test
public void mainErrorCompletable() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    PublishProcessor<Integer> source = PublishProcessor.create();
    TestObserver<Integer> to = source.single(-99).takeUntil(pp.ignoreElements()).test();
    source.onError(new TestException());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 65 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class SingleTakeUntilTest method untilSingleMainError.

@Test
public void untilSingleMainError() {
    SingleSubject<Integer> main = SingleSubject.create();
    SingleSubject<Integer> other = SingleSubject.create();
    TestObserver<Integer> to = main.takeUntil(other).test();
    assertTrue("Main no observers?", main.hasObservers());
    assertTrue("Other no observers?", other.hasObservers());
    main.onError(new TestException());
    assertFalse("Main has observers?", main.hasObservers());
    assertFalse("Other has observers?", other.hasObservers());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)656 Test (org.junit.Test)555 IOException (java.io.IOException)95 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)90 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)81 Disposable (io.reactivex.rxjava3.disposables.Disposable)56 InOrder (org.mockito.InOrder)54 TestObserver (io.reactivex.rxjava3.observers.TestObserver)47 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)47 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)40 Observable (io.reactivex.rxjava3.core.Observable)38 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)20 Action (io.reactivex.rxjava3.functions.Action)20 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)20 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)18 Observer (io.reactivex.rxjava3.core.Observer)15 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)15 Assert (org.junit.Assert)15 java.util (java.util)13 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)12