use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableSourceThrows.
@Test
public void delayWithObservableSourceThrows() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> delay = PublishSubject.create();
Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return delay;
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.delay(delayFunc).subscribe(o);
source.onNext(1);
source.onError(new TestException());
delay.onNext(1);
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableSubscriptionFunctionThrows.
@Test
public void delayWithObservableSubscriptionFunctionThrows() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> delay = PublishSubject.create();
Supplier<Observable<Integer>> subFunc = new Supplier<Observable<Integer>>() {
@Override
public Observable<Integer> get() {
throw new TestException();
}
};
Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return delay;
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.delay(Observable.defer(subFunc), delayFunc).subscribe(o);
source.onNext(1);
delay.onNext(1);
source.onNext(2);
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableSubscriptionRunCompletion.
@Test
public void delayWithObservableSubscriptionRunCompletion() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> sdelay = PublishSubject.create();
final PublishSubject<Integer> delay = PublishSubject.create();
Supplier<Observable<Integer>> subFunc = new Supplier<Observable<Integer>>() {
@Override
public Observable<Integer> get() {
return sdelay;
}
};
Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return delay;
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.delay(Observable.defer(subFunc), delayFunc).subscribe(o);
source.onNext(1);
sdelay.onComplete();
source.onNext(2);
delay.onNext(2);
inOrder.verify(o).onNext(2);
inOrder.verifyNoMoreInteractions();
verify(o, never()).onError(any(Throwable.class));
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableDelayThrows.
@Test
public void delayWithObservableDelayThrows() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> delay = PublishSubject.create();
Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return delay;
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.delay(delayFunc).subscribe(o);
source.onNext(1);
delay.onError(new TestException());
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableAsTimed.
@Test
public void delayWithObservableAsTimed() {
Observable<Long> source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3);
final Observable<Long> delayer = Observable.timer(500L, TimeUnit.MILLISECONDS, scheduler);
Function<Long, Observable<Long>> delayFunc = new Function<Long, Observable<Long>>() {
@Override
public Observable<Long> apply(Long t1) {
return delayer;
}
};
Observable<Long> delayed = source.delay(delayFunc);
delayed.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS);
verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(1500L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(0L);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(2400L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(2500L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(1L);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(3400L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(3500L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(2L);
verify(observer, times(1)).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
Aggregations