use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class TestObserverTest method errorInPredicate.
@Test
public void errorInPredicate() {
TestObserver<Object> to = new TestObserver<>();
to.onError(new RuntimeException());
try {
to.assertError(new Predicate<Throwable>() {
@Override
public boolean test(Throwable throwable) throws Exception {
throw new TestException();
}
});
} catch (TestException ex) {
// expected
return;
}
fail("Error in predicate but not thrown!");
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class SerializedObserverTest method onNextOnErrorRace.
@Test
public void onNextOnErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestObserver<Integer> to = new TestObserver<>();
final SerializedObserver<Integer> so = new SerializedObserver<>(to);
Disposable d = Disposable.empty();
so.onSubscribe(d);
final Throwable ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
so.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
so.onNext(1);
}
};
TestHelper.race(r1, r2);
to.awaitDone(5, TimeUnit.SECONDS).assertError(ex).assertNotComplete();
assertTrue(to.values().size() <= 1);
}
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class CompletableSwitchOnNextTest method delaySwitch.
@Test
public void delaySwitch() {
PublishProcessor<Completable> pp = PublishProcessor.create();
TestObserver<Void> to = Completable.switchOnNextDelayError(pp).test();
assertTrue(pp.hasSubscribers());
to.assertEmpty();
CompletableSubject cs1 = CompletableSubject.create();
CompletableSubject cs2 = CompletableSubject.create();
pp.onNext(cs1);
assertTrue(cs1.hasObservers());
pp.onNext(cs2);
assertFalse(cs1.hasObservers());
assertTrue(cs2.hasObservers());
assertTrue(cs2.hasObservers());
cs2.onError(new TestException());
assertTrue(pp.hasSubscribers());
to.assertEmpty();
pp.onComplete();
to.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class CompletableTimeoutTest method ambRace.
@Test
public void ambRace() {
TestObserver<Void> to = new TestObserver<>();
to.onSubscribe(Disposable.empty());
CompositeDisposable cd = new CompositeDisposable();
AtomicBoolean once = new AtomicBoolean();
TimeOutObserver a = new TimeOutObserver(cd, once, to);
a.onComplete();
a.onComplete();
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
a.onError(new TestException());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class CompletableAmbTest method untilCompletableOtherError.
@Test
public void untilCompletableOtherError() {
CompletableSubject main = CompletableSubject.create();
CompletableSubject other = CompletableSubject.create();
TestObserver<Void> to = main.ambWith(other).test();
assertTrue("Main no observers?", main.hasObservers());
assertTrue("Other no observers?", other.hasObservers());
other.onError(new TestException());
assertFalse("Main has observers?", main.hasObservers());
assertFalse("Other has observers?", other.hasObservers());
to.assertFailure(TestException.class);
}
Aggregations