use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class DeferredScalarObserverTest method disposedAfterOnNext.
@Test
public void disposedAfterOnNext() {
final TestObserver<Integer> to = new TestObserver<>();
TakeLast source = new TakeLast(new Observer<Integer>() {
Disposable upstream;
@Override
public void onSubscribe(Disposable d) {
this.upstream = d;
to.onSubscribe(d);
}
@Override
public void onNext(Integer value) {
to.onNext(value);
upstream.dispose();
}
@Override
public void onError(Throwable e) {
to.onError(e);
}
@Override
public void onComplete() {
to.onComplete();
}
});
source.onSubscribe(Disposable.empty());
source.onNext(1);
source.onComplete();
to.assertValue(1).assertNoErrors().assertNotComplete();
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class DeferredScalarObserverTest method dispose.
@Test
public void dispose() {
TestObserver<Integer> to = new TestObserver<>();
TakeFirst source = new TakeFirst(to);
Disposable d = Disposable.empty();
source.onSubscribe(d);
assertFalse(d.isDisposed());
to.dispose();
assertTrue(d.isDisposed());
assertTrue(source.isDisposed());
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class MaybeAmbTest method innerErrorRace.
@Test
public void innerErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp0 = PublishProcessor.create();
final PublishProcessor<Integer> pp1 = PublishProcessor.create();
final TestObserver<Integer> to = Maybe.amb(Arrays.asList(pp0.singleElement(), pp1.singleElement())).test();
final TestException ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
pp0.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
pp1.onError(ex);
}
};
TestHelper.race(r1, r2);
to.assertFailure(TestException.class);
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class MaybeDelaySubscriptionTest method timedTestScheduler.
@Test
public void timedTestScheduler() {
TestScheduler scheduler = new TestScheduler();
TestObserver<Integer> to = Maybe.just(1).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler).test();
to.assertEmpty();
scheduler.advanceTimeBy(99, TimeUnit.MILLISECONDS);
to.assertEmpty();
scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
to.assertResult(1);
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class MaybeDelayTest method delayedErrorOnError.
@Test
public void delayedErrorOnError() {
final TestScheduler scheduler = new TestScheduler();
final TestObserver<?> observer = Maybe.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);
}
Aggregations