Search in sources :

Example 46 with TestException

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

the class MaybeCreateTest method onErrorThrows.

@Test
public void onErrorThrows() {
    Maybe.create(new MaybeOnSubscribe<Object>() {

        @Override
        public void subscribe(MaybeEmitter<Object> e) throws Exception {
            Disposable d = Disposable.empty();
            e.setDisposable(d);
            try {
                e.onError(new IOException());
                fail("Should have thrown");
            } catch (TestException ex) {
            // expected
            }
            assertTrue(d.isDisposed());
            assertTrue(e.isDisposed());
        }
    }).subscribe(new MaybeObserver<Object>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onSuccess(Object value) {
        }

        @Override
        public void onError(Throwable e) {
            throw new TestException();
        }

        @Override
        public void onComplete() {
        }
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 47 with TestException

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

the class MaybeConcatArrayTest method errorAfterTermination.

@Test
public void errorAfterTermination() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final MaybeObserver<?>[] o = { null };
        Maybe.concatArrayDelayError(Maybe.just(1), Maybe.error(new IOException()), new Maybe<Integer>() {

            @Override
            protected void subscribeActual(MaybeObserver<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onSuccess(2);
                o[0] = observer;
            }
        }).test().assertFailure(IOException.class, 1, 2);
        o[0].onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 48 with TestException

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

the class MaybeDelayTest method delayedErrorOnError.

@Test
public void delayedErrorOnError() {
    final TestScheduler scheduler = new TestScheduler();
    final TestObserver<?> observer = Maybe.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) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 49 with TestException

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

the class MaybeDoFinallyTest method actionThrowsConditional.

@Test
public void actionThrowsConditional() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Maybe.just(1).doFinally(new Action() {

            @Override
            public void run() throws Exception {
                throw new TestException();
            }
        }).filter(Functions.alwaysTrue()).test().assertResult(1).dispose();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 50 with TestException

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

the class MaybeBlockingSubscribeTest method oneArgErrorAsync.

@Test
public void oneArgErrorAsync() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<Integer> success = mock(Consumer.class);
        Maybe.<Integer>error(new TestException()).delay(50, TimeUnit.MILLISECONDS, Schedulers.computation()).blockingSubscribe(success);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        verify(success, never()).accept(any());
    });
}
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