Search in sources :

Example 61 with TestException

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

the class FlowableUnsubscribeOnTest method signalAfterDispose.

@Test
public void signalAfterDispose() {
    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();
            }
        }.unsubscribeOn(Schedulers.single()).take(1).test().assertResult(1);
        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) Test(org.junit.Test)

Example 62 with TestException

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

the class FlowableWindowWithStartEndFlowableTest method endError.

@Test
public void endError() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    PublishProcessor<Integer> start = PublishProcessor.create();
    final PublishProcessor<Integer> end = PublishProcessor.create();
    TestSubscriber<Integer> to = source.window(start, new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer v) throws Exception {
            return end;
        }
    }).flatMap(Functions.<Flowable<Integer>>identity()).test();
    start.onNext(1);
    end.onError(new TestException());
    to.assertFailure(TestException.class);
    assertFalse("Source has observers!", source.hasSubscribers());
    assertFalse("Start has observers!", start.hasSubscribers());
    assertFalse("End has observers!", end.hasSubscribers());
}
Also used : TestException(io.reactivex.exceptions.TestException) TestException(io.reactivex.exceptions.TestException)

Example 63 with TestException

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

the class FlowableSkipTimedTest method testSkipTimedErrorBeforeTime.

@Test
public void testSkipTimedErrorBeforeTime() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Integer> source = PublishProcessor.create();
    Flowable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
    Subscriber<Object> o = TestHelper.mockSubscriber();
    result.subscribe(o);
    source.onNext(1);
    source.onNext(2);
    source.onNext(3);
    source.onError(new TestException());
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    InOrder inOrder = inOrder(o);
    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) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 64 with TestException

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

the class FlowableTakeLastTimedTest method takeLastTimedThrowingSource.

@Test
public void takeLastTimedThrowingSource() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Object> source = PublishProcessor.create();
    Flowable<Object> result = source.takeLast(1, TimeUnit.SECONDS, scheduler);
    Subscriber<Object> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    result.subscribe(o);
    // T: 0ms
    source.onNext(1);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 250ms
    source.onNext(2);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 500ms
    source.onNext(3);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 750ms
    source.onNext(4);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 1000ms
    source.onNext(5);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 1250ms
    source.onError(new TestException());
    inOrder.verify(o, times(1)).onError(any(TestException.class));
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 65 with TestException

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

the class FlowableTakeTimedTest method testTakeTimedErrorAfterTime.

@Test
public void testTakeTimedErrorAfterTime() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Integer> source = PublishProcessor.create();
    Flowable<Integer> result = source.take(1, TimeUnit.SECONDS, scheduler);
    Subscriber<Object> o = TestHelper.mockSubscriber();
    result.subscribe(o);
    source.onNext(1);
    source.onNext(2);
    source.onNext(3);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    source.onNext(4);
    source.onError(new TestException());
    InOrder inOrder = inOrder(o);
    inOrder.verify(o).onNext(1);
    inOrder.verify(o).onNext(2);
    inOrder.verify(o).onNext(3);
    inOrder.verify(o).onComplete();
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onNext(4);
    verify(o, never()).onError(any(TestException.class));
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.exceptions.TestException) TestScheduler(io.reactivex.schedulers.TestScheduler) 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