Search in sources :

Example 56 with TestException

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

the class FlowableElementAtTest method badSourceObservable.

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

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposables.empty());
                observer.onNext(1);
                observer.onNext(2);
                observer.onError(new TestException());
                observer.onComplete();
            }
        }.elementAt(0).toFlowable().test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) Observer(io.reactivex.Observer) Observable(io.reactivex.Observable)

Example 57 with TestException

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

the class FlowableFilterTest method sourceIgnoresCancelConditional.

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

            @Override
            public void subscribe(Subscriber<? super Integer> s) {
                ConditionalSubscriber<? super Integer> cs = (ConditionalSubscriber<? super Integer>) s;
                cs.onSubscribe(new BooleanSubscription());
                cs.tryOnNext(1);
                cs.tryOnNext(2);
                cs.onError(new IOException());
                cs.onComplete();
            }
        }).filter(new Predicate<Integer>() {

            @Override
            public boolean test(Integer v) throws Exception {
                return true;
            }
        }).filter(new Predicate<Integer>() {

            @Override
            public boolean test(Integer v) throws Exception {
                throw new TestException();
            }
        }).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) IOException(java.io.IOException) IOException(java.io.IOException) TestException(io.reactivex.exceptions.TestException)

Example 58 with TestException

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

the class FlowableFilterTest method sourceIgnoresCancel.

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

            @Override
            public void subscribe(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onNext(1);
                s.onNext(2);
                s.onError(new IOException());
                s.onComplete();
            }
        }).filter(new Predicate<Integer>() {

            @Override
            public boolean test(Integer v) throws Exception {
                throw new TestException();
            }
        }).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) IOException(java.io.IOException) IOException(java.io.IOException) TestException(io.reactivex.exceptions.TestException)

Example 59 with TestException

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

the class FlowableMapTest method mapFilterMapperCrashFused.

@Test
public void mapFilterMapperCrashFused() {
    TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueSubscription.ANY);
    Flowable.range(1, 2).hide().map(new Function<Integer, Integer>() {

        @Override
        public Integer apply(Integer v) throws Exception {
            throw new TestException();
        }
    }).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) throws Exception {
            return true;
        }
    }).subscribe(ts);
    ts.assertOf(SubscriberFusion.<Integer>assertFuseable()).assertOf(SubscriberFusion.<Integer>assertFusionMode(QueueSubscription.NONE)).assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.exceptions.TestException) IOException(java.io.IOException) TestException(io.reactivex.exceptions.TestException)

Example 60 with TestException

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

the class FlowableMapTest method sourceIgnoresCancel.

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

            @Override
            public void subscribe(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onNext(1);
                s.onNext(2);
                s.onError(new IOException());
                s.onComplete();
            }
        }).map(new Function<Integer, Object>() {

            @Override
            public Object apply(Integer v) throws Exception {
                throw new TestException();
            }
        }).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) IOException(java.io.IOException) IOException(java.io.IOException) TestException(io.reactivex.exceptions.TestException)

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