use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableDebounceTest method debounceWithError.
@Test
public void debounceWithError() {
Observable<String> source = Observable.unsafeCreate(new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> observer) {
observer.onSubscribe(Disposable.empty());
Exception error = new TestException();
// Should be published since "two" will arrive after the timeout expires.
publishNext(observer, 100, "one");
// Should be skipped since onError will arrive before the timeout expires.
publishNext(observer, 600, "two");
// Should be published as soon as the timeout expires.
publishError(observer, 700, error);
}
});
Observable<String> sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(observer);
scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
// 100 + 400 means it triggers at 500
scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS);
inOrder.verify(observer).onNext("one");
scheduler.advanceTimeTo(701, TimeUnit.MILLISECONDS);
inOrder.verify(observer).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableDeferTest method deferFunctionThrows.
@Test
public void deferFunctionThrows() throws Throwable {
Supplier<Observable<String>> factory = mock(Supplier.class);
when(factory.get()).thenThrow(new TestException());
Observable<String> result = Observable.defer(factory);
Observer<String> o = TestHelper.mockObserver();
result.subscribe(o);
verify(o).onError(any(TestException.class));
verify(o, never()).onNext(any(String.class));
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.core.Observer 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.core.Observer 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.core.Observer 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();
}
Aggregations