Search in sources :

Example 81 with Function

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

the class FlowableTimeoutWithSelectorTest method testTimeoutSelectorNormal1.

@Test(timeout = 2000)
public void testTimeoutSelectorNormal1() {
    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;
        }
    };
    Flowable<Integer> other = Flowable.fromIterable(Arrays.asList(100));
    Subscriber<Object> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    source.timeout(timeout, timeoutFunc, other).subscribe(o);
    source.onNext(1);
    source.onNext(2);
    source.onNext(3);
    timeout.onNext(1);
    inOrder.verify(o).onNext(1);
    inOrder.verify(o).onNext(2);
    inOrder.verify(o).onNext(3);
    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 82 with Function

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

the class FlowableTimeoutWithSelectorTest method testTimeoutSelectorFirstFlowableThrows.

@Test
public void testTimeoutSelectorFirstFlowableThrows() {
    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;
        }
    };
    Flowable<Integer> other = Flowable.fromIterable(Arrays.asList(100));
    Subscriber<Object> o = TestHelper.mockSubscriber();
    source.timeout(Flowable.<Integer>error(new TestException()), timeoutFunc, other).subscribe(o);
    verify(o).onError(any(TestException.class));
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : Function(io.reactivex.functions.Function) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 83 with Function

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

the class FlowableTimeoutWithSelectorTest method testTimeoutSelectorWithFirstTimeoutFirstAndNoOtherFlowable.

@Test
public void testTimeoutSelectorWithFirstTimeoutFirstAndNoOtherFlowable() {
    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 PublishProcessor.create();
        }
    };
    Subscriber<Object> o = TestHelper.mockSubscriber();
    source.timeout(timeout, timeoutFunc).subscribe(o);
    timeout.onNext(1);
    InOrder inOrder = inOrder(o);
    inOrder.verify(o).onError(isA(TimeoutException.class));
    inOrder.verifyNoMoreInteractions();
}
Also used : Function(io.reactivex.functions.Function) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 84 with Function

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

the class ObservableDebounceTest method debounceSelectorNormal1.

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

        @Override
        public Observable<Integer> apply(Integer t1) {
            return debouncer;
        }
    };
    Observer<Object> o = TestHelper.mockObserver();
    InOrder inOrder = inOrder(o);
    source.debounce(debounceSel).subscribe(o);
    source.onNext(1);
    debouncer.onNext(1);
    source.onNext(2);
    source.onNext(3);
    source.onNext(4);
    debouncer.onNext(2);
    source.onNext(5);
    source.onComplete();
    inOrder.verify(o).onNext(1);
    inOrder.verify(o).onNext(4);
    inOrder.verify(o).onNext(5);
    inOrder.verify(o).onComplete();
    verify(o, never()).onError(any(Throwable.class));
}
Also used : Function(io.reactivex.functions.Function) InOrder(org.mockito.InOrder)

Example 85 with Function

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

the class ObservableOnErrorResumeNextViaFunctionTest method testResumeNextWithAsyncExecution.

@Test
public void testResumeNextWithAsyncExecution() {
    final AtomicReference<Throwable> receivedException = new AtomicReference<Throwable>();
    Subscription s = mock(Subscription.class);
    TestObservable w = new TestObservable(s, "one");
    Function<Throwable, Observable<String>> resume = new Function<Throwable, Observable<String>>() {

        @Override
        public Observable<String> apply(Throwable t1) {
            receivedException.set(t1);
            return Observable.just("twoResume", "threeResume");
        }
    };
    Observable<String> o = Observable.unsafeCreate(w).onErrorResumeNext(resume);
    Observer<String> observer = TestHelper.mockObserver();
    o.subscribe(observer);
    try {
        w.t.join();
    } catch (InterruptedException e) {
        fail(e.getMessage());
    }
    verify(observer, Mockito.never()).onError(any(Throwable.class));
    verify(observer, times(1)).onComplete();
    verify(observer, times(1)).onNext("one");
    verify(observer, Mockito.never()).onNext("two");
    verify(observer, Mockito.never()).onNext("three");
    verify(observer, times(1)).onNext("twoResume");
    verify(observer, times(1)).onNext("threeResume");
    assertNotNull(receivedException.get());
}
Also used : Function(io.reactivex.functions.Function) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscription(org.reactivestreams.Subscription)

Aggregations

Function (io.reactivex.functions.Function)135 Disposable (io.reactivex.disposables.Disposable)45 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)38 List (java.util.List)36 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