Search in sources :

Example 26 with TestException

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();
            }
        });
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 27 with 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();
}
Also used : TestException(io.reactivex.exceptions.TestException)

Example 28 with TestException

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);
}
Also used : TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Subscription(org.reactivestreams.Subscription)

Example 29 with TestException

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);
}
Also used : TestException(io.reactivex.exceptions.TestException) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 30 with TestException

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);
}
Also used : TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.exceptions.TestException)417 Test (org.junit.Test)255 InOrder (org.mockito.InOrder)35 IOException (java.io.IOException)28 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)26 TestObserver (io.reactivex.observers.TestObserver)26 Observable (io.reactivex.Observable)24 Function (io.reactivex.functions.Function)24 TestSubscriber (io.reactivex.subscribers.TestSubscriber)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 TestScheduler (io.reactivex.schedulers.TestScheduler)11 Observer (io.reactivex.Observer)8 QueueDisposable (io.reactivex.internal.fuseable.QueueDisposable)8 Disposable (io.reactivex.disposables.Disposable)7 CrashingIterable (io.reactivex.internal.util.CrashingIterable)6 Action (io.reactivex.functions.Action)5 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 ObserveOnObserver (io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver)2 ScalarDisposable (io.reactivex.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)2 FutureSubscriber (io.reactivex.internal.subscribers.FutureSubscriber)2