use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableDelaySubscriptionOtherTest method testNoPrematureSubscription.
@Test
public void testNoPrematureSubscription() {
PublishSubject<Object> other = PublishSubject.create();
TestObserver<Integer> ts = new TestObserver<Integer>();
final AtomicInteger subscribed = new AtomicInteger();
Observable.just(1).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.onNext(1);
Assert.assertEquals("No subscription", 1, subscribed.get());
ts.assertValue(1);
ts.assertNoErrors();
ts.assertComplete();
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableCacheTest method testValuesAndThenError.
@Test
public void testValuesAndThenError() {
Observable<Integer> source = Observable.range(1, 10).concatWith(Observable.<Integer>error(new TestException())).cache();
TestObserver<Integer> ts = new TestObserver<Integer>();
source.subscribe(ts);
ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
ts.assertNotComplete();
ts.assertError(TestException.class);
TestObserver<Integer> ts2 = new TestObserver<Integer>();
source.subscribe(ts2);
ts2.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
ts2.assertNotComplete();
ts2.assertError(TestException.class);
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableCacheTest method unsafeChildThrows.
@Test
@Ignore("2.x consumers are not allowed to throw")
public void unsafeChildThrows() {
final AtomicInteger count = new AtomicInteger();
Observable<Integer> source = Observable.range(1, 100).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer t) {
count.getAndIncrement();
}
}).cache();
TestObserver<Integer> ts = new TestObserver<Integer>() {
@Override
public void onNext(Integer t) {
throw new TestException();
}
};
source.subscribe(ts);
Assert.assertEquals(100, count.get());
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(TestException.class);
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableReplayTest method unsafeChildThrows.
@Test
@Ignore("onNext should not throw")
public void unsafeChildThrows() {
final AtomicInteger count = new AtomicInteger();
Observable<Integer> source = Observable.range(1, 100).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer t) {
count.getAndIncrement();
}
}).replay().autoConnect();
TestObserver<Integer> ts = new TestObserver<Integer>() {
@Override
public void onNext(Integer t) {
throw new TestException();
}
};
source.subscribe(ts);
Assert.assertEquals(100, count.get());
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(TestException.class);
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableDelaySubscriptionOtherTest method testNoMultipleSubscriptions.
@Test
public void testNoMultipleSubscriptions() {
PublishSubject<Object> other = PublishSubject.create();
TestObserver<Integer> ts = new TestObserver<Integer>();
final AtomicInteger subscribed = new AtomicInteger();
Observable.just(1).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.onNext(1);
other.onNext(2);
Assert.assertEquals("No subscription", 1, subscribed.get());
ts.assertValue(1);
ts.assertNoErrors();
ts.assertComplete();
}
Aggregations