Search in sources :

Example 71 with TestException

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

the class ExecutorSchedulerDelayedRunnableTest method delayedRunnableCrash.

@Test(expected = TestException.class)
@SuppressUndeliverable
public void delayedRunnableCrash() {
    DelayedRunnable dl = new DelayedRunnable(new Runnable() {

        @Override
        public void run() {
            throw new TestException();
        }
    });
    dl.run();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) DelayedRunnable(io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.DelayedRunnable) DelayedRunnable(io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.DelayedRunnable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test) SuppressUndeliverable(io.reactivex.rxjava3.testsupport.SuppressUndeliverable)

Example 72 with TestException

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

the class SingleSwitchOnNextTest method delaySwitch.

@Test
public void delaySwitch() {
    PublishProcessor<Single<Integer>> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = Single.switchOnNextDelayError(pp).test();
    assertTrue(pp.hasSubscribers());
    ts.assertEmpty();
    SingleSubject<Integer> ss1 = SingleSubject.create();
    SingleSubject<Integer> ss2 = SingleSubject.create();
    pp.onNext(ss1);
    assertTrue(ss1.hasObservers());
    pp.onNext(ss2);
    assertFalse(ss1.hasObservers());
    assertTrue(ss2.hasObservers());
    assertTrue(ss2.hasObservers());
    ss2.onError(new TestException());
    assertTrue(pp.hasSubscribers());
    ts.assertEmpty();
    pp.onComplete();
    ts.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 73 with TestException

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

the class SingleZipArrayTest method innerErrorRace.

@Test
public void innerErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp0 = PublishProcessor.create();
            final PublishProcessor<Integer> pp1 = PublishProcessor.create();
            final TestObserver<Object> to = Single.zip(pp0.single(0), pp1.single(0), addString).test();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp0.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    pp1.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            to.assertFailure(TestException.class);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 74 with TestException

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

the class SingleConcatMapCompletableTest method mapperThrows.

@Test
public void mapperThrows() {
    final boolean[] b = { false };
    Single.just(1).concatMapCompletable(new Function<Integer, Completable>() {

        @Override
        public Completable apply(Integer t) throws Exception {
            throw new TestException();
        }
    }).test().assertFailure(TestException.class);
    assertFalse(b[0]);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 75 with TestException

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

the class SingleCreateTest method tryOnError.

@Test
public void tryOnError() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final Boolean[] response = { null };
        Single.create(new SingleOnSubscribe<Object>() {

            @Override
            public void subscribe(SingleEmitter<Object> e) throws Exception {
                e.onSuccess(1);
                response[0] = e.tryOnError(new TestException());
            }
        }).test().assertResult(1);
        assertFalse(response[0]);
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) 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