Search in sources :

Example 46 with Function

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

the class XFlatMapTest method maybeMaybe.

@Test
public void maybeMaybe() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> ts = Maybe.just(1).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());
            }
        }).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 47 with Function

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

the class XFlatMapTest method observerSingle.

@Test
public void observerSingle() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> ts = 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();
        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 48 with Function

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

the class XFlatMapTest method flowableMaybe.

@Test
public void flowableMaybe() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestSubscriber<Integer> ts = Flowable.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 49 with Function

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

the class FlowableTimeoutWithSelectorTest method testTimeoutSelectorTimeoutFirst.

@Test
public void testTimeoutSelectorTimeoutFirst() throws InterruptedException {
    Flowable<Integer> source = Flowable.<Integer>never();
    final PublishProcessor<Integer> timeout = PublishProcessor.create();
    Function<Integer, Flowable<Integer>> timeoutFunc = new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            return timeout;
        }
    };
    Flowable<Integer> other = Flowable.fromIterable(Arrays.asList(100));
    Subscriber<Object> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    source.timeout(timeout, timeoutFunc, other).subscribe(o);
    timeout.onNext(1);
    inOrder.verify(o).onNext(100);
    inOrder.verify(o).onComplete();
    verify(o, never()).onError(any(Throwable.class));
}
Also used : Function(io.reactivex.functions.Function) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 50 with Function

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

the class FlowableTimeoutWithSelectorTest method testTimeoutSelectorWithTimeoutFirstAndNoOtherFlowable.

@Test
public void testTimeoutSelectorWithTimeoutFirstAndNoOtherFlowable() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    final PublishProcessor<Integer> timeout = PublishProcessor.create();
    Function<Integer, Flowable<Integer>> timeoutFunc = new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            return timeout;
        }
    };
    Subscriber<Object> o = TestHelper.mockSubscriber();
    source.timeout(PublishProcessor.create(), timeoutFunc).subscribe(o);
    source.onNext(1);
    timeout.onNext(1);
    InOrder inOrder = inOrder(o);
    inOrder.verify(o).onNext(1);
    inOrder.verify(o).onError(isA(TimeoutException.class));
    inOrder.verifyNoMoreInteractions();
}
Also used : Function(io.reactivex.functions.Function) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Aggregations

Function (io.reactivex.functions.Function)65 Test (org.junit.Test)27 TestException (io.reactivex.exceptions.TestException)24 InOrder (org.mockito.InOrder)21 Disposable (io.reactivex.disposables.Disposable)12 Observable (io.reactivex.Observable)10 NonNull (io.reactivex.annotations.NonNull)10 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)10 BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)6 List (java.util.List)4 RequestBody (okhttp3.RequestBody)4 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)3 Person (io.requery.test.model.Person)3 ArrayList (java.util.ArrayList)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 User (com.khmelenko.lab.varis.network.response.User)2 Phone (io.requery.test.model.Phone)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Headers (okhttp3.Headers)2