use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableOnErrorResumeNextTest method functionThrowsError.
/**
* Test that when a function throws an exception this is propagated through onError.
*/
@Test
public void functionThrowsError() {
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) {
throw new RuntimeException("exception from function");
}
};
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());
}
// we should get the "one" value before the error
verify(observer, times(1)).onNext("one");
// we should have received an onError call on the Observer since the resume function threw an exception
verify(observer, times(1)).onError(any(Throwable.class));
verify(observer, times(0)).onComplete();
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableOnErrorResumeNextTest method resumeNextWithAsyncExecution.
@Test
public void resumeNextWithAsyncExecution() {
final AtomicReference<Throwable> receivedException = new AtomicReference<>();
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());
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableSkipLastTimedTest method skipLastTimedErrorBeforeTime.
@Test
public void skipLastTimedErrorBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skipLast(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onError(new TestException());
scheduler.advanceTimeBy(1050, TimeUnit.MILLISECONDS);
verify(o).onError(any(TestException.class));
verify(o, never()).onComplete();
verify(o, never()).onNext(any());
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableSkipTimedTest method skipTimedFinishBeforeTime.
@Test
public void skipTimedFinishBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onComplete();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
InOrder inOrder = inOrder(o);
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableSkipTimedTest method skipTimed.
@Test
public void skipTimed() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
source.onNext(5);
source.onNext(6);
source.onComplete();
InOrder inOrder = inOrder(o);
inOrder.verify(o, never()).onNext(1);
inOrder.verify(o, never()).onNext(2);
inOrder.verify(o, never()).onNext(3);
inOrder.verify(o).onNext(4);
inOrder.verify(o).onNext(5);
inOrder.verify(o).onNext(6);
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onError(any(Throwable.class));
}
Aggregations