use of io.reactivex.observers.TestObserver in project retrofit by square.
the class AsyncTest method success.
@Test
public void success() throws InterruptedException {
TestObserver<Void> observer = new TestObserver<>();
service.completable().subscribe(observer);
assertFalse(observer.await(1, SECONDS));
server.enqueue(new MockResponse());
observer.awaitTerminalEvent(1, SECONDS);
observer.assertComplete();
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class CompletableCacheTest method crossDisposeOnError.
@Test
public void crossDisposeOnError() {
PublishSubject<Integer> ps = PublishSubject.create();
final TestObserver<Void> ts1 = new TestObserver<Void>();
final TestObserver<Void> ts2 = new TestObserver<Void>() {
@Override
public void onError(Throwable ex) {
super.onError(ex);
ts1.cancel();
}
};
Completable c = ps.ignoreElements().cache();
c.subscribe(ts2);
c.subscribe(ts1);
ps.onError(new TestException());
ts1.assertEmpty();
ts2.assertFailure(TestException.class);
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableDebounceTest method debounceWithTimeBackpressure.
@Test
public void debounceWithTimeBackpressure() throws InterruptedException {
TestScheduler scheduler = new TestScheduler();
TestObserver<Integer> observer = new TestObserver<Integer>();
Observable.merge(Observable.just(1), Observable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler)).debounce(20, TimeUnit.MILLISECONDS, scheduler).take(1).subscribe(observer);
scheduler.advanceTimeBy(30, TimeUnit.MILLISECONDS);
observer.assertValue(2);
observer.assertTerminated();
observer.assertNoErrors();
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableDelaySubscriptionOtherTest method testNoSubscriptionIfOtherErrors.
@Test
public void testNoSubscriptionIfOtherErrors() {
PublishSubject<Object> other = PublishSubject.create();
TestObserver<Integer> ts = new TestObserver<Integer>();
final AtomicInteger subscribed = new AtomicInteger();
Observable.<Integer>error(new TestException()).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable d) {
subscribed.getAndIncrement();
}
}).delaySubscription(other).subscribe(ts);
ts.assertNotComplete();
ts.assertNoErrors();
ts.assertNoValues();
Assert.assertEquals("Premature subscription", 0, subscribed.get());
other.onError(new TestException());
Assert.assertEquals("Premature subscription", 0, subscribed.get());
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(TestException.class);
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableAmbTest method testSubscriptionOnlyHappensOnce.
@SuppressWarnings("unchecked")
@Test
public void testSubscriptionOnlyHappensOnce() throws InterruptedException {
final AtomicLong count = new AtomicLong();
Consumer<Disposable> incrementer = new Consumer<Disposable>() {
@Override
public void accept(Disposable s) {
count.incrementAndGet();
}
};
//this aync stream should emit first
Observable<Integer> o1 = Observable.just(1).doOnSubscribe(incrementer).delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation());
//this stream emits second
Observable<Integer> o2 = Observable.just(1).doOnSubscribe(incrementer).delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation());
TestObserver<Integer> ts = new TestObserver<Integer>();
Observable.ambArray(o1, o2).subscribe(ts);
ts.awaitTerminalEvent(5, TimeUnit.SECONDS);
ts.assertNoErrors();
assertEquals(2, count.get());
}
Aggregations