use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class CompletableSafeSubscribeTest method normalError.
@Test
public void normalError() throws Throwable {
TestHelper.withErrorTracking(errors -> {
CompletableObserver consumer = mock(CompletableObserver.class);
Completable.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());
});
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class CompletableSafeSubscribeTest method onErrorCrash.
@Test
public void onErrorCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
CompletableObserver consumer = mock(CompletableObserver.class);
doThrow(new TestException()).when(consumer).onError(any());
new Completable() {
@Override
protected void subscribeActual(@NonNull CompletableObserver 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 CompletableSafeSubscribeTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
CompletableObserver consumer = mock(CompletableObserver.class);
doThrow(new TestException()).when(consumer).onSubscribe(any());
Disposable d = Disposable.empty();
new Completable() {
@Override
protected void subscribeActual(@NonNull CompletableObserver observer) {
observer.onSubscribe(d);
// none of the following should arrive at the consumer
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 MaybeConsumersTest method onErrorCrash.
@Test
public void onErrorCrash() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
subscribeAutoDispose(processor, composite, this, new Consumer<Throwable>() {
@Override
public void accept(Throwable t) throws Exception {
throw new IOException(t);
}
}, this);
processor.onError(new IllegalArgumentException());
assertTrue(events.toString(), events.isEmpty());
TestHelper.assertError(errors, 0, CompositeException.class);
List<Throwable> inners = TestHelper.compositeList(errors.get(0));
TestHelper.assertError(inners, 0, IllegalArgumentException.class);
TestHelper.assertError(inners, 1, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class CompletableDoOnLifecycleTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
Action onDispose = mock(Action.class);
doThrow(new TestException("First")).when(onSubscribe).accept(any());
Disposable bs = Disposable.empty();
new Completable() {
@Override
protected void subscribeActual(CompletableObserver observer) {
observer.onSubscribe(bs);
observer.onError(new TestException("Second"));
observer.onComplete();
}
}.doOnLifecycle(onSubscribe, onDispose).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
assertTrue(bs.isDisposed());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
verify(onSubscribe).accept(any());
verify(onDispose, never()).run();
});
}
Aggregations