use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.
the class FlowableCreateTest method onCompleteCrash.
@Test
public void onCompleteCrash() {
for (BackpressureStrategy m : BackpressureStrategy.values()) {
Flowable.create(new FlowableOnSubscribe<Object>() {
@Override
public void subscribe(FlowableEmitter<Object> e) throws Exception {
Disposable d = Disposables.empty();
e.setDisposable(d);
try {
e.onComplete();
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
assertTrue(d.isDisposed());
}
}, m).subscribe(new FlowableSubscriber<Object>() {
@Override
public void onSubscribe(Subscription d) {
}
@Override
public void onNext(Object value) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
throw new TestException();
}
});
}
}
use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.
the class FlowableDefaultIfEmptyTest method testEmptyButClientThrows.
@Test
@Ignore("Subscribers should not throw")
public void testEmptyButClientThrows() {
final Subscriber<Integer> o = TestHelper.mockSubscriber();
Flowable.<Integer>empty().defaultIfEmpty(1).subscribe(new DefaultSubscriber<Integer>() {
@Override
public void onNext(Integer t) {
throw new TestException();
}
@Override
public void onError(Throwable e) {
o.onError(e);
}
@Override
public void onComplete() {
o.onComplete();
}
});
verify(o).onError(any(TestException.class));
verify(o, never()).onNext(any(Integer.class));
verify(o, never()).onComplete();
}
use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.
the class FlowableDelaySubscriptionOtherTest method testNoSubscriptionIfOtherErrors.
@Test
public void testNoSubscriptionIfOtherErrors() {
PublishProcessor<Object> other = PublishProcessor.create();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
final AtomicInteger subscribed = new AtomicInteger();
Flowable.<Integer>error(new TestException()).doOnSubscribe(new Consumer<Subscription>() {
@Override
public void accept(Subscription s) {
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.exceptions.TestException in project RxJava by ReactiveX.
the class FlowableBlockingTest method blockingSubscribeObserverError.
@Test
public void blockingSubscribeObserverError() {
final List<Object> list = new ArrayList<Object>();
final TestException ex = new TestException();
Flowable.range(1, 5).concatWith(Flowable.<Integer>error(ex)).subscribeOn(Schedulers.computation()).blockingSubscribe(new FlowableSubscriber<Object>() {
@Override
public void onSubscribe(Subscription d) {
d.request(Long.MAX_VALUE);
}
@Override
public void onNext(Object value) {
list.add(value);
}
@Override
public void onError(Throwable e) {
list.add(e);
}
@Override
public void onComplete() {
list.add(100);
}
});
assertEquals(Arrays.asList(1, 2, 3, 4, 5, ex), list);
}
use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.
the class FlowableBlockingTest method blockingSubscribeConsumerConsumerError.
@Test
public void blockingSubscribeConsumerConsumerError() {
final List<Object> list = new ArrayList<Object>();
TestException ex = new TestException();
Consumer<Object> cons = new Consumer<Object>() {
@Override
public void accept(Object v) throws Exception {
list.add(v);
}
};
Flowable.range(1, 5).concatWith(Flowable.<Integer>error(ex)).subscribeOn(Schedulers.computation()).blockingSubscribe(cons, cons);
assertEquals(Arrays.asList(1, 2, 3, 4, 5, ex), list);
}
Aggregations