use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableFromSupplierTest method shouldNotDeliverResultIfSubscriberUnsubscribedBeforeEmission.
@SuppressWarnings("unchecked")
@Test
public void shouldNotDeliverResultIfSubscriberUnsubscribedBeforeEmission() throws Throwable {
Supplier<String> func = mock(Supplier.class);
final CountDownLatch funcLatch = new CountDownLatch(1);
final CountDownLatch observerLatch = new CountDownLatch(1);
when(func.get()).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
observerLatch.countDown();
try {
funcLatch.await();
} catch (InterruptedException e) {
// It's okay, unsubscription causes Thread interruption
// Restoring interruption status of the Thread
Thread.currentThread().interrupt();
}
return "should_not_be_delivered";
}
});
Observable<String> fromSupplierObservable = Observable.fromSupplier(func);
Observer<Object> observer = TestHelper.mockObserver();
TestObserver<String> outer = new TestObserver<>(observer);
fromSupplierObservable.subscribeOn(Schedulers.computation()).subscribe(outer);
// Wait until func will be invoked
observerLatch.await();
// Unsubscribing before emission
outer.dispose();
// Emitting result
funcLatch.countDown();
// func must be invoked
verify(func).get();
// Observer must not be notified at all
verify(observer).onSubscribe(any(Disposable.class));
verifyNoMoreInteractions(observer);
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableReplayEagerTruncateTest method disposeNoNeedForResetTimeAndSIzeBound.
@Test
public void disposeNoNeedForResetTimeAndSIzeBound() {
PublishSubject<Integer> ps = PublishSubject.create();
ConnectableObservable<Integer> co = ps.replay(10, 10, TimeUnit.MINUTES, Schedulers.single(), true);
TestObserver<Integer> to = co.test();
Disposable d = co.connect();
ps.onNext(1);
d.dispose();
to = co.test();
to.assertEmpty();
co.connect();
to.assertEmpty();
ps.onNext(2);
to.assertValuesOnly(2);
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableResourceWrapperTest method onErrorDisposes.
@Test
public void onErrorDisposes() {
TestObserver<Object> to = new TestObserver<>();
ObserverResourceWrapper<Object> orw = new ObserverResourceWrapper<>(to);
Disposable d = Disposable.empty();
Disposable d1 = Disposable.empty();
orw.setResource(d1);
orw.onSubscribe(d);
orw.onError(new TestException());
assertTrue(d1.isDisposed());
to.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableMergeWithMaybeTest method cancelMainOnOtherError.
@Test
public void cancelMainOnOtherError() {
PublishSubject<Integer> ps = PublishSubject.create();
MaybeSubject<Integer> ms = MaybeSubject.create();
TestObserver<Integer> to = ps.mergeWith(ms).test();
assertTrue(ps.hasObservers());
assertTrue(ms.hasObservers());
ms.onError(new TestException());
to.assertFailure(TestException.class);
assertFalse("main has observers!", ps.hasObservers());
assertFalse("other has observers", ms.hasObservers());
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableMergeWithSingleTest method cancelOtherOnMainError.
@Test
public void cancelOtherOnMainError() {
PublishSubject<Integer> ps = PublishSubject.create();
SingleSubject<Integer> ss = SingleSubject.create();
TestObserver<Integer> to = ps.mergeWith(ss).test();
assertTrue(ps.hasObservers());
assertTrue(ss.hasObservers());
ps.onError(new TestException());
to.assertFailure(TestException.class);
assertFalse("main has observers!", ps.hasObservers());
assertFalse("other has observers", ss.hasObservers());
}
Aggregations