Search in sources :

Example 26 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class ObservableDematerializeTest method errorPassThru.

@Test
public void errorPassThru() {
    Exception exception = new Exception("test");
    Observable<Notification<Integer>> o = Observable.error(exception);
    Observable<Integer> dematerialize = o.dematerialize(Functions.<Notification<Integer>>identity());
    Observer<Integer> observer = TestHelper.mockObserver();
    dematerialize.subscribe(observer);
    verify(observer, times(1)).onError(exception);
    verify(observer, times(0)).onComplete();
    verify(observer, times(0)).onNext(any(Integer.class));
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 27 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class ObservableDoOnEachTest method onCompleteAfterCrash.

@Test
public void onCompleteAfterCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Observable.wrap(new ObservableSource<Object>() {

            @Override
            public void subscribe(Observer<? super Object> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onComplete();
            }
        }).doAfterTerminate(new Action() {

            @Override
            public void run() throws Exception {
                throw new IOException();
            }
        }).test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestObserver(io.reactivex.rxjava3.observers.TestObserver) IOException(java.io.IOException) IOException(java.io.IOException)

Example 28 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class ObservableDoOnEachTest method onCompleteCrash.

@Test
public void onCompleteCrash() {
    Observable.wrap(new ObservableSource<Object>() {

        @Override
        public void subscribe(Observer<? super Object> observer) {
            observer.onSubscribe(Disposable.empty());
            observer.onComplete();
        }
    }).doOnComplete(new Action() {

        @Override
        public void run() throws Exception {
            throw new IOException();
        }
    }).test().assertFailure(IOException.class);
}
Also used : TestObserver(io.reactivex.rxjava3.observers.TestObserver) IOException(java.io.IOException) IOException(java.io.IOException)

Example 29 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class ObservableFlatMapTest method flatMapTransformsMaxConcurrentNormal.

@Test
public void flatMapTransformsMaxConcurrentNormal() {
    final int m = 2;
    final AtomicInteger subscriptionCount = new AtomicInteger();
    Observable<Integer> onNext = composer(Observable.fromIterable(Arrays.asList(1, 2, 3)).observeOn(Schedulers.computation()), subscriptionCount, m).subscribeOn(Schedulers.computation());
    Observable<Integer> onComplete = composer(Observable.fromIterable(Arrays.asList(4)), subscriptionCount, m).subscribeOn(Schedulers.computation());
    Observable<Integer> onError = Observable.fromIterable(Arrays.asList(5));
    Observable<Integer> source = Observable.fromIterable(Arrays.asList(10, 20, 30));
    Observer<Object> o = TestHelper.mockObserver();
    TestObserverEx<Object> to = new TestObserverEx<>(o);
    Function<Throwable, Observable<Integer>> just = just(onError);
    source.flatMap(just(onNext), just, just0(onComplete), m).subscribe(to);
    to.awaitDone(1, TimeUnit.SECONDS);
    to.assertNoErrors();
    to.assertTerminated();
    verify(o, times(3)).onNext(1);
    verify(o, times(3)).onNext(2);
    verify(o, times(3)).onNext(3);
    verify(o).onNext(4);
    verify(o).onComplete();
    verify(o, never()).onNext(5);
    verify(o, never()).onError(any(Throwable.class));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Observable(io.reactivex.rxjava3.core.Observable)

Example 30 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class ObservableDebounceTest method before.

@Before
public void before() {
    scheduler = new TestScheduler();
    observer = TestHelper.mockObserver();
    innerScheduler = scheduler.createWorker();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Aggregations

Test (org.junit.Test)139 TestException (io.reactivex.rxjava3.exceptions.TestException)88 InOrder (org.mockito.InOrder)75 Observable (io.reactivex.rxjava3.core.Observable)49 Disposable (io.reactivex.rxjava3.disposables.Disposable)49 TestObserver (io.reactivex.rxjava3.observers.TestObserver)37 IOException (java.io.IOException)29 Observer (io.reactivex.rxjava3.core.Observer)23 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)11 Function (io.reactivex.rxjava3.functions.Function)10 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)6 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)5 io.reactivex.rxjava3.subjects (io.reactivex.rxjava3.subjects)5 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5