Search in sources :

Example 36 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowableCacheTest method testValuesAndThenError.

@Test
public void testValuesAndThenError() {
    Flowable<Integer> source = Flowable.range(1, 10).concatWith(Flowable.<Integer>error(new TestException())).cache();
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    source.subscribe(ts);
    ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    ts.assertNotComplete();
    ts.assertError(TestException.class);
    TestSubscriber<Integer> ts2 = new TestSubscriber<Integer>();
    source.subscribe(ts2);
    ts2.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    ts2.assertNotComplete();
    ts2.assertError(TestException.class);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber)

Example 37 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowableDetachTest method error.

@Test
public void error() {
    TestSubscriber<Object> ts = new TestSubscriber<Object>();
    Flowable.error(new TestException()).onTerminateDetach().subscribe(ts);
    ts.assertNoValues();
    ts.assertError(TestException.class);
    ts.assertNotComplete();
}
Also used : TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber)

Example 38 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowablePublishTest method testObserveOn.

@Test
public void testObserveOn() {
    ConnectableFlowable<Integer> co = Flowable.range(0, 1000).hide().publish();
    Flowable<Integer> obs = co.observeOn(Schedulers.computation());
    for (int i = 0; i < 1000; i++) {
        for (int j = 1; j < 6; j++) {
            List<TestSubscriber<Integer>> tss = new ArrayList<TestSubscriber<Integer>>();
            for (int k = 1; k < j; k++) {
                TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
                tss.add(ts);
                obs.subscribe(ts);
            }
            Disposable s = co.connect();
            for (TestSubscriber<Integer> ts : tss) {
                ts.awaitDone(5, TimeUnit.SECONDS).assertSubscribed().assertValueCount(1000).assertNoErrors().assertComplete();
            }
            s.dispose();
        }
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 39 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowablePublishTest method asyncFusedObserveOn.

@Test
public void asyncFusedObserveOn() {
    ConnectableFlowable<Integer> co = Flowable.range(0, 1000).observeOn(ImmediateThinScheduler.INSTANCE).publish();
    for (int i = 0; i < 1000; i++) {
        for (int j = 1; j < 6; j++) {
            List<TestSubscriber<Integer>> tss = new ArrayList<TestSubscriber<Integer>>();
            for (int k = 1; k < j; k++) {
                TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
                tss.add(ts);
                co.subscribe(ts);
            }
            Disposable s = co.connect();
            for (TestSubscriber<Integer> ts : tss) {
                ts.awaitDone(5, TimeUnit.SECONDS).assertSubscribed().assertValueCount(1000).assertNoErrors().assertComplete();
            }
            s.dispose();
        }
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 40 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowablePublishTest method syncFusedObserveOn.

@Test
public void syncFusedObserveOn() {
    ConnectableFlowable<Integer> co = Flowable.range(0, 1000).publish();
    Flowable<Integer> obs = co.observeOn(Schedulers.computation());
    for (int i = 0; i < 1000; i++) {
        for (int j = 1; j < 6; j++) {
            List<TestSubscriber<Integer>> tss = new ArrayList<TestSubscriber<Integer>>();
            for (int k = 1; k < j; k++) {
                TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
                tss.add(ts);
                obs.subscribe(ts);
            }
            Disposable s = co.connect();
            for (TestSubscriber<Integer> ts : tss) {
                ts.awaitDone(5, TimeUnit.SECONDS).assertSubscribed().assertValueCount(1000).assertNoErrors().assertComplete();
            }
            s.dispose();
        }
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Aggregations

TestSubscriber (io.reactivex.subscribers.TestSubscriber)65 Test (org.junit.Test)43 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)20 TestException (io.reactivex.exceptions.TestException)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 InOrder (org.mockito.InOrder)11 Disposable (io.reactivex.disposables.Disposable)9 TestScheduler (io.reactivex.schedulers.TestScheduler)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 BooleanSupplier (io.reactivex.functions.BooleanSupplier)5 ArrayDeque (java.util.ArrayDeque)5 Task (com.example.android.architecture.blueprints.todoapp.data.Task)2 Optional (com.google.common.base.Optional)2 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Subscriber (org.reactivestreams.Subscriber)2 Flowable (io.reactivex.Flowable)1 Worker (io.reactivex.Scheduler.Worker)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Action (io.reactivex.functions.Action)1