use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class ObservableBlockingTest method blockingSubscribeConsumerConsumerError.
@Test
public void blockingSubscribeConsumerConsumerError() {
final List<Object> list = new ArrayList<>();
TestException ex = new TestException();
Consumer<Object> cons = new Consumer<Object>() {
@Override
public void accept(Object v) throws Exception {
list.add(v);
}
};
Observable.range(1, 5).concatWith(Observable.<Integer>error(ex)).subscribeOn(Schedulers.computation()).blockingSubscribe(cons, cons);
assertEquals(Arrays.asList(1, 2, 3, 4, 5, ex), list);
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class MaybeSafeSubscribeTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") MaybeObserver<Integer> consumer = mock(MaybeObserver.class);
doThrow(new TestException()).when(consumer).onSubscribe(any());
Disposable d = Disposable.empty();
new Maybe<Integer>() {
@Override
protected void subscribeActual(@NonNull MaybeObserver<? super Integer> observer) {
observer.onSubscribe(d);
// none of the following should arrive at the consumer
observer.onSuccess(1);
observer.onError(new IOException());
observer.onComplete();
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verifyNoMoreInteractions();
assertTrue(d.isDisposed());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
TestHelper.assertUndeliverable(errors, 1, IOException.class);
});
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class MaybeSafeSubscribeTest method normalSuccess.
@Test
public void normalSuccess() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") MaybeObserver<Integer> consumer = mock(MaybeObserver.class);
Maybe.just(1).safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onSuccess(1);
order.verifyNoMoreInteractions();
assertTrue("" + errors, errors.isEmpty());
});
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class MaybeSafeSubscribeTest method onErrorCrash.
@Test
public void onErrorCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") MaybeObserver<Integer> consumer = mock(MaybeObserver.class);
doThrow(new TestException()).when(consumer).onError(any());
new Maybe<Integer>() {
@Override
protected void subscribeActual(@NonNull MaybeObserver<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
// none of the following should arrive at the consumer
observer.onError(new IOException());
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onError(any(IOException.class));
order.verifyNoMoreInteractions();
TestHelper.assertError(errors, 0, CompositeException.class);
CompositeException compositeException = (CompositeException) errors.get(0);
TestHelper.assertError(compositeException.getExceptions(), 0, IOException.class);
TestHelper.assertError(compositeException.getExceptions(), 1, TestException.class);
});
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class MaybeSafeSubscribeTest method normalError.
@Test
public void normalError() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") MaybeObserver<Integer> consumer = mock(MaybeObserver.class);
Maybe.<Integer>error(new TestException()).safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onError(any(TestException.class));
order.verifyNoMoreInteractions();
assertTrue("" + errors, errors.isEmpty());
});
}
Aggregations