Search in sources :

Example 86 with TestException

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

the class MaybeCacheTest method onlineError.

@Test
public void onlineError() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    Maybe<Integer> source = pp.singleElement().cache();
    assertFalse(pp.hasSubscribers());
    assertNotNull(((MaybeCache<Integer>) source).source.get());
    TestObserver<Integer> ts = source.test();
    assertNull(((MaybeCache<Integer>) source).source.get());
    assertTrue(pp.hasSubscribers());
    source.test(true).assertEmpty();
    ts.assertEmpty();
    pp.onError(new TestException());
    ts.assertFailure(TestException.class);
    source.test().assertFailure(TestException.class);
    source.test(true).assertEmpty();
}
Also used : TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 87 with TestException

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

the class MaybeCreateTest method onSuccessThrows.

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

        @Override
        public void subscribe(MaybeEmitter<Object> e) throws Exception {
            Disposable d = Disposables.empty();
            e.setDisposable(d);
            try {
                e.onSuccess(1);
                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) {
            throw new TestException();
        }

        @Override
        public void onError(Throwable e) {
        }

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

Example 88 with TestException

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

the class MaybeCreateTest method onCompleteThrows2.

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

        @Override
        public void subscribe(MaybeEmitter<Object> e) throws Exception {
            try {
                e.onComplete();
                fail("Should have thrown");
            } catch (TestException ex) {
            // expected
            }
            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) {
        }

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

Example 89 with TestException

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

the class MaybeDelaySubscriptionTest method withPublisherCallAfterTerminalEvent.

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

            @Override
            protected void subscribeActual(Subscriber<? super Integer> observer) {
                observer.onSubscribe(new BooleanSubscription());
                observer.onNext(1);
                observer.onError(new TestException());
                observer.onComplete();
                observer.onNext(2);
            }
        };
        Maybe.just(1).delaySubscription(f).test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 90 with TestException

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

the class MaybeDoAfterSuccessTest method consumerThrows.

@Test
public void consumerThrows() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Maybe.just(1).doAfterSuccess(new Consumer<Integer>() {

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

Aggregations

TestException (io.reactivex.exceptions.TestException)417 Test (org.junit.Test)255 InOrder (org.mockito.InOrder)35 IOException (java.io.IOException)28 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)26 TestObserver (io.reactivex.observers.TestObserver)26 Observable (io.reactivex.Observable)24 Function (io.reactivex.functions.Function)24 TestSubscriber (io.reactivex.subscribers.TestSubscriber)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 TestScheduler (io.reactivex.schedulers.TestScheduler)11 Observer (io.reactivex.Observer)8 QueueDisposable (io.reactivex.internal.fuseable.QueueDisposable)8 Disposable (io.reactivex.disposables.Disposable)7 CrashingIterable (io.reactivex.internal.util.CrashingIterable)6 Action (io.reactivex.functions.Action)5 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 ObserveOnObserver (io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver)2 ScalarDisposable (io.reactivex.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)2 FutureSubscriber (io.reactivex.internal.subscribers.FutureSubscriber)2