use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.
the class ObservableBlockingTest method blockingSubscribeObserverError.
@Test
public void blockingSubscribeObserverError() {
final List<Object> list = new ArrayList<Object>();
final TestException ex = new TestException();
Observable.range(1, 5).concatWith(Observable.<Integer>error(ex)).subscribeOn(Schedulers.computation()).blockingSubscribe(new Observer<Object>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Object value) {
list.add(value);
}
@Override
public void onError(Throwable e) {
list.add(e);
}
@Override
public void onComplete() {
list.add(100);
}
});
assertEquals(Arrays.asList(1, 2, 3, 4, 5, ex), list);
}
use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.
the class ObservableBufferTest method bufferWithStartEndStartThrows.
@Test
public void bufferWithStartEndStartThrows() {
PublishSubject<Integer> start = PublishSubject.create();
Function<Integer, Observable<Integer>> end = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return Observable.never();
}
};
PublishSubject<Integer> source = PublishSubject.create();
Observable<List<Integer>> result = source.buffer(start, end);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
start.onNext(1);
source.onNext(1);
source.onNext(2);
start.onError(new TestException());
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
verify(o).onError(any(TestException.class));
}
use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.
the class ObservableBufferTest method bufferWithSizeThrows.
@Test
public void bufferWithSizeThrows() {
PublishSubject<Integer> source = PublishSubject.create();
Observable<List<Integer>> result = source.buffer(2);
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onError(new TestException());
inOrder.verify(o).onNext(Arrays.asList(1, 2));
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(Arrays.asList(3));
verify(o, never()).onComplete();
}
use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.
the class ObservableCacheTest method testValuesAndThenError.
@Test
public void testValuesAndThenError() {
Observable<Integer> source = Observable.range(1, 10).concatWith(Observable.<Integer>error(new TestException())).cache();
TestObserver<Integer> ts = new TestObserver<Integer>();
source.subscribe(ts);
ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
ts.assertNotComplete();
ts.assertError(TestException.class);
TestObserver<Integer> ts2 = new TestObserver<Integer>();
source.subscribe(ts2);
ts2.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
ts2.assertNotComplete();
ts2.assertError(TestException.class);
}
use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.
the class ObservableCacheTest method unsafeChildThrows.
@Test
@Ignore("2.x consumers are not allowed to throw")
public void unsafeChildThrows() {
final AtomicInteger count = new AtomicInteger();
Observable<Integer> source = Observable.range(1, 100).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer t) {
count.getAndIncrement();
}
}).cache();
TestObserver<Integer> ts = new TestObserver<Integer>() {
@Override
public void onNext(Integer t) {
throw new TestException();
}
};
source.subscribe(ts);
Assert.assertEquals(100, count.get());
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(TestException.class);
}
Aggregations