Search in sources :

Example 56 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class XFlatMapTest method observableObservable.

@Test
public void observableObservable() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Observable.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Observable<Integer>>() {

            @Override
            public Observable<Integer> apply(Integer v) throws Exception {
                sleep();
                return Observable.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 57 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class XFlatMapTest method observerSingle.

@Test
public void observerSingle() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Observable.just(1).subscribeOn(Schedulers.io()).flatMapSingle(new Function<Integer, Single<Integer>>() {

            @Override
            public Single<Integer> apply(Integer v) throws Exception {
                sleep();
                return Single.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 58 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class XFlatMapTest method singleCombiner.

@Test
public void singleCombiner() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Single.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Single<Integer>>() {

            @Override
            public Single<Integer> apply(Integer v) throws Exception {
                sleep();
                return Single.<Integer>error(new TestException());
            }
        }, (a, b) -> a + b).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) List(java.util.List) CyclicBarrier(java.util.concurrent.CyclicBarrier) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) io.reactivex.rxjava3.functions(io.reactivex.rxjava3.functions) Publisher(org.reactivestreams.Publisher) Assert.assertTrue(org.junit.Assert.assertTrue) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) org.junit(org.junit) RxJavaPlugins(io.reactivex.rxjava3.plugins.RxJavaPlugins) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 59 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class XFlatMapTest method singleNotificationError.

@Test
public void singleNotificationError() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Single.<Integer>error(new TestException()).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Single<Integer>>() {

            @Override
            public Single<Integer> apply(Integer v) throws Exception {
                sleep();
                return Single.<Integer>error(new TestException());
            }
        }, new Function<Throwable, Single<Integer>>() {

            @Override
            public Single<Integer> apply(Throwable v) throws Exception {
                sleep();
                return Single.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 60 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class XFlatMapTest method maybeNotificationEmpty.

@Test
public void maybeNotificationEmpty() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Maybe.<Integer>empty().subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Maybe<Integer>>() {

            @Override
            public Maybe<Integer> apply(Integer v) throws Exception {
                sleep();
                return Maybe.<Integer>error(new TestException());
            }
        }, new Function<Throwable, Maybe<Integer>>() {

            @Override
            public Maybe<Integer> apply(Throwable v) throws Exception {
                sleep();
                return Maybe.<Integer>error(new TestException());
            }
        }, new Supplier<Maybe<Integer>>() {

            @Override
            public Maybe<Integer> get() throws Exception {
                sleep();
                return Maybe.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Aggregations

Test (org.junit.Test)225 TestException (io.reactivex.rxjava3.exceptions.TestException)169 TestObserver (io.reactivex.rxjava3.observers.TestObserver)90 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)35 Disposable (io.reactivex.rxjava3.disposables.Disposable)34 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)27 TargetApi (android.annotation.TargetApi)21 Observable (io.reactivex.rxjava3.core.Observable)19 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)19 IOException (java.io.IOException)19 Matchers.anyString (org.mockito.Matchers.anyString)16 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)13 Action (io.reactivex.rxjava3.functions.Action)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 InOrder (org.mockito.InOrder)7 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)6 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)6 List (java.util.List)6 Assert (org.junit.Assert)6 Activity (android.app.Activity)5