Search in sources :

Example 96 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class SingleFlatMapTest method flatMapPublisherCancelDuringSingle.

@Test
public void flatMapPublisherCancelDuringSingle() {
    final AtomicBoolean disposed = new AtomicBoolean();
    TestSubscriberEx<Integer> ts = Single.<Integer>never().doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            disposed.set(true);
        }
    }).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

        @Override
        public Publisher<Integer> apply(Integer v) throws Exception {
            return Flowable.range(v, 5);
        }
    }).to(TestHelper.<Integer>testConsumer()).assertNoValues().assertNotTerminated();
    assertFalse(disposed.get());
    ts.cancel();
    assertTrue(disposed.get());
    ts.assertNotTerminated();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 97 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class SingleFlatMapTest method flatMapPublisherCancelDuringFlowable.

@Test
public void flatMapPublisherCancelDuringFlowable() {
    final AtomicBoolean disposed = new AtomicBoolean();
    TestSubscriberEx<Integer> ts = Single.just(1).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

        @Override
        public Publisher<Integer> apply(Integer v) throws Exception {
            return Flowable.<Integer>never().doOnCancel(new Action() {

                @Override
                public void run() throws Exception {
                    disposed.set(true);
                }
            });
        }
    }).to(TestHelper.<Integer>testConsumer()).assertNoValues().assertNotTerminated();
    assertFalse(disposed.get());
    ts.cancel();
    assertTrue(disposed.get());
    ts.assertNotTerminated();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 98 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class SingleFlatMapTest method flatMapPublisherSingleError.

@Test
public void flatMapPublisherSingleError() {
    final TestException ex = new TestException();
    Single.<Integer>error(ex).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

        @Override
        public Publisher<Integer> apply(Integer v) throws Exception {
            return Flowable.just(1);
        }
    }).test().assertNoValues().assertError(ex);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 99 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class SingleFlatMapTest method flatMapPublisherMapperThrows.

@Test
public void flatMapPublisherMapperThrows() {
    final TestException ex = new TestException();
    Single.just(1).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

        @Override
        public Publisher<Integer> apply(Integer v) throws Exception {
            throw ex;
        }
    }).test().assertNoValues().assertError(ex);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 100 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class SchedulerWhenTest method disposed.

@Test
public void disposed() {
    SchedulerWhen sw = new SchedulerWhen(new Function<Flowable<Flowable<Completable>>, Completable>() {

        @Override
        public Completable apply(Flowable<Flowable<Completable>> v) throws Exception {
            return Completable.never();
        }
    }, Schedulers.single());
    assertFalse(sw.isDisposed());
    sw.dispose();
    assertTrue(sw.isDisposed());
}
Also used : SchedulerWhen(io.reactivex.rxjava3.internal.schedulers.SchedulerWhen) TestException(io.reactivex.rxjava3.exceptions.TestException) Flowable(io.reactivex.rxjava3.core.Flowable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)97 TestException (io.reactivex.rxjava3.exceptions.TestException)78 Observable (io.reactivex.rxjava3.core.Observable)41 InOrder (org.mockito.InOrder)36 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 Function (io.reactivex.rxjava3.functions.Function)20 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 IOException (java.io.IOException)13 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)9 TestObserver (io.reactivex.rxjava3.observers.TestObserver)9 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)9 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)8 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)7 Observer (io.reactivex.rxjava3.core.Observer)7 Function (org.apache.cassandra.cql3.functions.Function)7 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)6 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)6 EmptyScheduler (io.reactivex.rxjava3.android.testutil.EmptyScheduler)5