use of io.reactivex.rxjava3.annotations.NonNull 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.annotations.NonNull in project RxJava by ReactiveX.
the class MaybeSafeSubscribeTest method onSuccessCrash.
@Test
public void onSuccessCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") MaybeObserver<Integer> consumer = mock(MaybeObserver.class);
doThrow(new TestException()).when(consumer).onSuccess(any());
new Maybe<Integer>() {
@Override
protected void subscribeActual(@NonNull MaybeObserver<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onSuccess(1);
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onSuccess(1);
order.verifyNoMoreInteractions();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
});
}
use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.
the class ObservableFlatMapStreamTest method eventsIgnoredAfterCrash.
@Test
public void eventsIgnoredAfterCrash() {
AtomicInteger calls = new AtomicInteger();
new Observable<Integer>() {
@Override
protected void subscribeActual(@NonNull Observer<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onNext(1);
observer.onNext(2);
observer.onComplete();
}
}.flatMapStream(v -> {
calls.getAndIncrement();
throw new TestException();
}).take(1).test().assertFailure(TestException.class);
assertEquals(1, calls.get());
}
use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.
the class SingleSafeSubscribeTest method onErrorCrash.
@Test
public void onErrorCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
doThrow(new TestException()).when(consumer).onError(any());
new Single<Integer>() {
@Override
protected void subscribeActual(@NonNull SingleObserver<? 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.annotations.NonNull in project RxJava by ReactiveX.
the class SingleTimeoutTest method timeoutBeforeOnSubscribeFromMain.
@Test
public void timeoutBeforeOnSubscribeFromMain() {
Disposable d = Disposable.empty();
new Single<Integer>() {
@Override
protected void subscribeActual(@NonNull SingleObserver<? super @NonNull Integer> observer) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
observer.onSubscribe(d);
}
}.timeout(1, TimeUnit.MILLISECONDS, Single.just(1)).test().awaitDone(5, TimeUnit.SECONDS).assertResult(1);
assertTrue(d.isDisposed());
}
Aggregations