Search in sources :

Example 41 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)

Example 42 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 43 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 44 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 45 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)

Aggregations

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