Search in sources :

Example 36 with TestException

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

the class CompletableDisposeOnTest method error.

@Test
public void error() {
    TestScheduler scheduler = new TestScheduler();
    final int[] call = { 0 };
    Completable.error(new TestException()).doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            call[0]++;
        }
    }).unsubscribeOn(scheduler).test().assertFailure(TestException.class);
    scheduler.triggerActions();
    assertEquals(0, call[0]);
}
Also used : Action(io.reactivex.functions.Action) TestException(io.reactivex.exceptions.TestException) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 37 with TestException

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

the class FlowableDoAfterNextTest method errorConditional.

@Test
public void errorConditional() {
    Flowable.<Integer>error(new TestException()).doAfterNext(afterNext).filter(Functions.alwaysTrue()).subscribeWith(ts).assertFailure(TestException.class);
    assertTrue(values.isEmpty());
}
Also used : TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 38 with TestException

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

the class FlowableDelayTest method testErrorRunsBeforeOnNext.

@Test
public void testErrorRunsBeforeOnNext() {
    TestScheduler test = new TestScheduler();
    PublishProcessor<Integer> ps = PublishProcessor.create();
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    ps.delay(1, TimeUnit.SECONDS, test).subscribe(ts);
    ps.onNext(1);
    test.advanceTimeBy(500, TimeUnit.MILLISECONDS);
    ps.onError(new TestException());
    test.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertNoValues();
    ts.assertError(TestException.class);
    ts.assertNotComplete();
}
Also used : TestException(io.reactivex.exceptions.TestException)

Example 39 with TestException

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

the class FlowableDelayTest method testDelayWithFlowableDelayFunctionThrows.

@Test
public void testDelayWithFlowableDelayFunctionThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            throw new TestException();
        }
    };
    Subscriber<Object> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    source.delay(delayFunc).subscribe(o);
    source.onNext(1);
    inOrder.verify(o).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.exceptions.TestException)

Example 40 with TestException

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

the class FlowableDelayTest method onErrorFinal.

@Test
public void onErrorFinal() {
    TestScheduler scheduler = new TestScheduler();
    Flowable.error(new TestException()).delay(1, TimeUnit.MILLISECONDS, scheduler).subscribe(new DisposableSubscriber<Object>() {

        @Override
        public void onNext(Object value) {
        }

        @Override
        public void onError(Throwable e) {
            throw new TestException();
        }

        @Override
        public void onComplete() {
        }
    });
    try {
        scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
        fail("Should have thrown");
    } catch (TestException ex) {
    // expected
    }
}
Also used : TestException(io.reactivex.exceptions.TestException)

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