Search in sources :

Example 1 with Function

use of io.reactivex.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method flowableSingle.

@Test
public void flowableSingle() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestSubscriber<Integer> ts = Flowable.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();
        Thread.sleep(50);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Function(io.reactivex.functions.Function) TestException(io.reactivex.exceptions.TestException)

Example 2 with Function

use of io.reactivex.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method observableFlowable.

@Test
public void observableFlowable() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> ts = 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();
        Thread.sleep(50);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Function(io.reactivex.functions.Function) TestException(io.reactivex.exceptions.TestException)

Example 3 with Function

use of io.reactivex.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method singleCompletable.

@Test
public void singleCompletable() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Void> ts = Single.just(1).subscribeOn(Schedulers.io()).flatMapCompletable(new Function<Integer, Completable>() {

            @Override
            public Completable apply(Integer v) throws Exception {
                sleep();
                return Completable.error(new TestException());
            }
        }).test();
        cb.await();
        Thread.sleep(50);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Function(io.reactivex.functions.Function) TestException(io.reactivex.exceptions.TestException)

Example 4 with Function

use of io.reactivex.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method observerMaybe.

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

            @Override
            public Maybe<Integer> apply(Integer v) throws Exception {
                sleep();
                return Maybe.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        Thread.sleep(50);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Function(io.reactivex.functions.Function) TestException(io.reactivex.exceptions.TestException)

Example 5 with Function

use of io.reactivex.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method maybeCompletable.

@Test
public void maybeCompletable() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Void> ts = Maybe.just(1).subscribeOn(Schedulers.io()).flatMapCompletable(new Function<Integer, Completable>() {

            @Override
            public Completable apply(Integer v) throws Exception {
                sleep();
                return Completable.error(new TestException());
            }
        }).test();
        cb.await();
        Thread.sleep(50);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Function(io.reactivex.functions.Function) TestException(io.reactivex.exceptions.TestException)

Aggregations

Function (io.reactivex.functions.Function)134 Disposable (io.reactivex.disposables.Disposable)44 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)37 List (java.util.List)35 Test (org.junit.Test)35 TestException (io.reactivex.exceptions.TestException)24 InOrder (org.mockito.InOrder)21 ArrayList (java.util.ArrayList)18 Observable (io.reactivex.Observable)14 NonNull (io.reactivex.annotations.NonNull)14 Reply (io.rx_cache2.Reply)9 FavoriteException (com.dante.exception.FavoriteException)8 MessageException (com.dante.exception.MessageException)8 Consumer (io.reactivex.functions.Consumer)8 BaseResult (com.dante.data.model.BaseResult)6 BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)6 DynamicKeyGroup (io.rx_cache2.DynamicKeyGroup)6 EvictDynamicKeyGroup (io.rx_cache2.EvictDynamicKeyGroup)6 ApiResponse (com.xinshang.audient.model.entities.ApiResponse)5 Flowable (io.reactivex.Flowable)5