Search in sources :

Example 86 with Function

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

the class ObservableTimeoutWithSelectorTest method testTimeoutSelectorSubsequentObservableThrows.

@Test
public void testTimeoutSelectorSubsequentObservableThrows() {
    PublishSubject<Integer> source = PublishSubject.create();
    final PublishSubject<Integer> timeout = PublishSubject.create();
    Function<Integer, Observable<Integer>> timeoutFunc = new Function<Integer, Observable<Integer>>() {

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

Example 87 with Function

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

the class ObservableTimeoutWithSelectorTest method testTimeoutSelectorWithTimeoutFirstAndNoOtherObservable.

@Test
public void testTimeoutSelectorWithTimeoutFirstAndNoOtherObservable() {
    PublishSubject<Integer> source = PublishSubject.create();
    final PublishSubject<Integer> timeout = PublishSubject.create();
    Function<Integer, Observable<Integer>> timeoutFunc = new Function<Integer, Observable<Integer>>() {

        @Override
        public Observable<Integer> apply(Integer t1) {
            return timeout;
        }
    };
    Observer<Object> o = TestHelper.mockObserver();
    source.timeout(PublishSubject.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) Observable(io.reactivex.Observable) Test(org.junit.Test)

Example 88 with Function

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

the class ObservableTimeoutWithSelectorTest method testTimeoutSelectorSubsequentThrows.

@Test
public void testTimeoutSelectorSubsequentThrows() {
    PublishSubject<Integer> source = PublishSubject.create();
    final PublishSubject<Integer> timeout = PublishSubject.create();
    Function<Integer, Observable<Integer>> timeoutFunc = new Function<Integer, Observable<Integer>>() {

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

Example 89 with Function

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

the class ObservableTimeoutWithSelectorTest method testTimeoutSelectorWithFirstTimeoutFirstAndNoOtherObservable.

@Test
public void testTimeoutSelectorWithFirstTimeoutFirstAndNoOtherObservable() {
    PublishSubject<Integer> source = PublishSubject.create();
    final PublishSubject<Integer> timeout = PublishSubject.create();
    Function<Integer, Observable<Integer>> timeoutFunc = new Function<Integer, Observable<Integer>>() {

        @Override
        public Observable<Integer> apply(Integer t1) {
            return PublishSubject.create();
        }
    };
    Observer<Object> o = TestHelper.mockObserver();
    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) Observable(io.reactivex.Observable) Test(org.junit.Test)

Example 90 with Function

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

the class ObservableTimeoutWithSelectorTest method testTimeoutSelectorFirstObservableThrows.

@Test
public void testTimeoutSelectorFirstObservableThrows() {
    PublishSubject<Integer> source = PublishSubject.create();
    final PublishSubject<Integer> timeout = PublishSubject.create();
    Function<Integer, Observable<Integer>> timeoutFunc = new Function<Integer, Observable<Integer>>() {

        @Override
        public Observable<Integer> apply(Integer t1) {
            return timeout;
        }
    };
    Observable<Integer> other = Observable.fromIterable(Arrays.asList(100));
    Observer<Object> o = TestHelper.mockObserver();
    source.timeout(Observable.<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) Observable(io.reactivex.Observable) Test(org.junit.Test)

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