Search in sources :

Example 21 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableBufferTest method boundaryBoundaryError.

@SuppressWarnings("unchecked")
@Test
public void boundaryBoundaryError() {
    PublishProcessor<Object> pp = PublishProcessor.create();
    TestSubscriber<Collection<Object>> ts = pp.buffer(Functions.justCallable(Flowable.error(new TestException())), new Callable<Collection<Object>>() {

        @Override
        public Collection<Object> call() throws Exception {
            return new ArrayList<Object>();
        }
    }).test();
    pp.onError(new TestException());
    ts.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.exceptions.TestException)

Example 22 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableBufferTest method bufferWithSizeThrows.

@Test
public void bufferWithSizeThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    Flowable<List<Integer>> result = source.buffer(2);
    Subscriber<Object> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    result.subscribe(o);
    source.onNext(1);
    source.onNext(2);
    source.onNext(3);
    source.onError(new TestException());
    inOrder.verify(o).onNext(Arrays.asList(1, 2));
    inOrder.verify(o).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onNext(Arrays.asList(3));
    verify(o, never()).onComplete();
}
Also used : TestException(io.reactivex.exceptions.TestException)

Example 23 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableCacheTest method unsafeChildThrows.

@Test
@Ignore("RS subscribers should not throw")
public void unsafeChildThrows() {
    final AtomicInteger count = new AtomicInteger();
    Flowable<Integer> source = Flowable.range(1, 100).doOnNext(new Consumer<Integer>() {

        @Override
        public void accept(Integer t) {
            count.getAndIncrement();
        }
    }).cache();
    TestSubscriber<Integer> ts = new TestSubscriber<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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.subscribers.TestSubscriber)

Example 24 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class BlockingFlowableNextTest method testOnError.

@Test
public void testOnError() throws Throwable {
    FlowableProcessor<String> obs = PublishProcessor.create();
    Iterator<String> it = obs.blockingNext().iterator();
    obs.onError(new TestException());
    try {
        it.hasNext();
        fail("Expected an TestException");
    } catch (TestException e) {
    // successful
    }
    assertErrorAfterObservableFail(it);
}
Also used : TestException(io.reactivex.exceptions.TestException)

Example 25 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableAllTest method predicateThrowsObservable.

@Test
public void predicateThrowsObservable() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> observer) {
                observer.onSubscribe(new BooleanSubscription());
                observer.onNext(1);
                observer.onNext(2);
                observer.onError(new TestException());
                observer.onComplete();
            }
        }.all(new Predicate<Integer>() {

            @Override
            public boolean test(Integer v) throws Exception {
                throw new TestException();
            }
        }).toFlowable().test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber)

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