Search in sources :

Example 76 with TestException

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

the class ObservableAnyTest method predicateThrowsSuppressOthers.

@Test
public void predicateThrowsSuppressOthers() {
    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 IOException());
                observer.onComplete();
            }
        }.any(new Predicate<Integer>() {

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

Example 77 with TestException

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

the class ObservableCreateTest method onCompleteCrash.

@Test
public void onCompleteCrash() {
    Observable.create(new ObservableOnSubscribe<Object>() {

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

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onNext(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 78 with TestException

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

the class ObservableCreateTest method onErrorCrash.

@Test
public void onErrorCrash() {
    Observable.create(new ObservableOnSubscribe<Object>() {

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

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onNext(Object value) {
        }

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

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

Example 79 with TestException

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

the class ObservableDebounceTest method debounceSelectorObservableThrows.

@Test
public void debounceSelectorObservableThrows() {
    PublishSubject<Integer> source = PublishSubject.create();
    Function<Integer, Observable<Integer>> debounceSel = new Function<Integer, Observable<Integer>>() {

        @Override
        public Observable<Integer> apply(Integer t1) {
            return Observable.error(new TestException());
        }
    };
    Observer<Object> o = TestHelper.mockObserver();
    source.debounce(debounceSel).subscribe(o);
    source.onNext(1);
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
    verify(o).onError(any(TestException.class));
}
Also used : Function(io.reactivex.functions.Function) TestException(io.reactivex.exceptions.TestException)

Example 80 with TestException

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

the class ObservableDefaultIfEmptyTest method testEmptyButClientThrows.

@Test
@Ignore("Subscribers should not throw")
public void testEmptyButClientThrows() {
    final Observer<Integer> o = TestHelper.mockObserver();
    Observable.<Integer>empty().defaultIfEmpty(1).subscribe(new DefaultObserver<Integer>() {

        @Override
        public void onNext(Integer t) {
            throw new TestException();
        }

        @Override
        public void onError(Throwable e) {
            o.onError(e);
        }

        @Override
        public void onComplete() {
            o.onComplete();
        }
    });
    verify(o).onError(any(TestException.class));
    verify(o, never()).onNext(any(Integer.class));
    verify(o, never()).onComplete();
}
Also used : 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