use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class MaybeCreateTest method onCompleteThrows2.
@Test
public void onCompleteThrows2() {
Maybe.create(new MaybeOnSubscribe<Object>() {
@Override
public void subscribe(MaybeEmitter<Object> e) throws Exception {
try {
e.onComplete();
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
assertTrue(e.isDisposed());
}
}).subscribe(new MaybeObserver<Object>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onSuccess(Object value) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
throw new TestException();
}
});
}
use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class MaybeCreateTest method onErrorThrows.
@Test
public void onErrorThrows() {
Maybe.create(new MaybeOnSubscribe<Object>() {
@Override
public void subscribe(MaybeEmitter<Object> e) throws Exception {
Disposable d = Disposable.empty();
e.setDisposable(d);
try {
e.onError(new IOException());
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
assertTrue(d.isDisposed());
assertTrue(e.isDisposed());
}
}).subscribe(new MaybeObserver<Object>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onSuccess(Object value) {
}
@Override
public void onError(Throwable e) {
throw new TestException();
}
@Override
public void onComplete() {
}
});
}
use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.
the class SingleSafeSubscribeTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
doThrow(new TestException()).when(consumer).onSubscribe(any());
Disposable d = Disposable.empty();
new Single<Integer>() {
@Override
protected void subscribeActual(@NonNull SingleObserver<? super Integer> observer) {
observer.onSubscribe(d);
// none of the following should arrive at the consumer
observer.onSuccess(1);
observer.onError(new IOException());
}
}.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.disposables.Disposable 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.disposables.Disposable 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());
}
Aggregations