Search in sources :

Example 76 with TestException

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

the class SingleCreateTest method createConsumerThrowsResource.

@Test
public void createConsumerThrowsResource() {
    Single.create(new SingleOnSubscribe<Object>() {

        @Override
        public void subscribe(SingleEmitter<Object> s) throws Exception {
            Disposable d = Disposable.empty();
            s.setDisposable(d);
            try {
                s.onSuccess(1);
                fail("Should have thrown");
            } catch (TestException ex) {
            // expected
            }
            assertTrue(d.isDisposed());
        }
    }).subscribe(new SingleObserver<Object>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onSuccess(Object value) {
            throw new TestException();
        }

        @Override
        public void onError(Throwable e) {
        }
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 77 with TestException

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

the class SingleDelayTest method delayedErrorOnError.

@Test
public void delayedErrorOnError() {
    final TestScheduler scheduler = new TestScheduler();
    final TestObserver<?> observer = Single.error(new TestException()).delay(5, TimeUnit.SECONDS, scheduler, true).test();
    scheduler.advanceTimeTo(2, TimeUnit.SECONDS);
    observer.assertNoErrors();
    scheduler.advanceTimeTo(5, TimeUnit.SECONDS);
    observer.assertError(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 78 with TestException

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

the class SingleDetachTest method errorDetaches.

@Test
public void errorDetaches() throws Exception {
    Disposable d = Disposable.empty();
    final WeakReference<Disposable> wr = new WeakReference<>(d);
    TestObserver<Integer> to = new Single<Integer>() {

        @Override
        protected void subscribeActual(SingleObserver<? super Integer> observer) {
            observer.onSubscribe(wr.get());
            observer.onError(new TestException());
            observer.onError(new IOException());
        }
    }.onTerminateDetach().test();
    d = null;
    System.gc();
    Thread.sleep(200);
    to.assertFailure(TestException.class);
    assertNull(wr.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) WeakReference(java.lang.ref.WeakReference) IOException(java.io.IOException) Test(org.junit.Test)

Example 79 with TestException

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

the class SingleDoOnLifecycleTest method onDisposeCrash.

@Test
public void onDisposeCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
        Action onDispose = mock(Action.class);
        doThrow(new TestException("First")).when(onDispose).run();
        SingleSubject<Integer> ss = SingleSubject.create();
        TestObserver<Integer> to = ss.doOnLifecycle(onSubscribe, onDispose).test();
        assertTrue(ss.hasObservers());
        to.dispose();
        assertFalse(ss.hasObservers());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
        verify(onSubscribe).accept(any());
        verify(onDispose).run();
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 80 with TestException

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

the class SingleFlatMapTest method mapperThrows.

@Test
public void mapperThrows() {
    final boolean[] b = { false };
    Single.just(1).flatMapCompletable(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)

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