use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.
the class SingleCreateTest method createConsumerThrowsResource.
@Test
public void createConsumerThrowsResource() {
Single.create(new SingleOnSubscribe<Object>() {
@Override
public void subscribe(SingleEmitter<Object> s) throws Exception {
Disposable d = Disposable.empty();
s.setDisposable(d);
try {
s.onSuccess(1);
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
assertTrue(d.isDisposed());
}
}).subscribe(new SingleObserver<Object>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onSuccess(Object value) {
throw new TestException();
}
@Override
public void onError(Throwable e) {
}
});
}
use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.
the class SingleDelayTest method delayedErrorOnError.
@Test
public void delayedErrorOnError() {
final TestScheduler scheduler = new TestScheduler();
final TestObserver<?> observer = Single.error(new TestException()).delay(5, TimeUnit.SECONDS, scheduler, true).test();
scheduler.advanceTimeTo(2, TimeUnit.SECONDS);
observer.assertNoErrors();
scheduler.advanceTimeTo(5, TimeUnit.SECONDS);
observer.assertError(TestException.class);
}
use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.
the class SingleDetachTest method errorDetaches.
@Test
public void errorDetaches() throws Exception {
Disposable d = Disposable.empty();
final WeakReference<Disposable> wr = new WeakReference<>(d);
TestObserver<Integer> to = new Single<Integer>() {
@Override
protected void subscribeActual(SingleObserver<? super Integer> observer) {
observer.onSubscribe(wr.get());
observer.onError(new TestException());
observer.onError(new IOException());
}
}.onTerminateDetach().test();
d = null;
System.gc();
Thread.sleep(200);
to.assertFailure(TestException.class);
assertNull(wr.get());
}
use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.
the class SingleDoOnLifecycleTest method onDisposeCrash.
@Test
public void onDisposeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
Action onDispose = mock(Action.class);
doThrow(new TestException("First")).when(onDispose).run();
SingleSubject<Integer> ss = SingleSubject.create();
TestObserver<Integer> to = ss.doOnLifecycle(onSubscribe, onDispose).test();
assertTrue(ss.hasObservers());
to.dispose();
assertFalse(ss.hasObservers());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
verify(onSubscribe).accept(any());
verify(onDispose).run();
});
}
use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.
the class SingleFlatMapTest method mapperThrows.
@Test
public void mapperThrows() {
final boolean[] b = { false };
Single.just(1).flatMapCompletable(new Function<Integer, Completable>() {
@Override
public Completable apply(Integer t) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
assertFalse(b[0]);
}
Aggregations