Search in sources :

Example 16 with Supplier

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

the class CompletableFromSupplierTest method fromSupplierTwice.

@Test
public void fromSupplierTwice() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Supplier<Object> supplier = new Supplier<Object>() {

        @Override
        public Object get() throws Exception {
            atomicInteger.incrementAndGet();
            return null;
        }
    };
    Completable.fromSupplier(supplier).test().assertResult();
    assertEquals(1, atomicInteger.get());
    Completable.fromSupplier(supplier).test().assertResult();
    assertEquals(2, atomicInteger.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Supplier(io.reactivex.rxjava3.functions.Supplier) Test(org.junit.Test)

Example 17 with Supplier

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

the class MaybeFromSupplierTest method fromSupplierTwice.

@Test
public void fromSupplierTwice() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Supplier<Object> supplier = new Supplier<Object>() {

        @Override
        public Object get() throws Exception {
            atomicInteger.incrementAndGet();
            return null;
        }
    };
    Maybe.fromSupplier(supplier).test().assertResult();
    assertEquals(1, atomicInteger.get());
    Maybe.fromSupplier(supplier).test().assertResult();
    assertEquals(2, atomicInteger.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Supplier(io.reactivex.rxjava3.functions.Supplier) Test(org.junit.Test)

Example 18 with Supplier

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

the class FlowableDelayTest method delayWithFlowableSubscriptionThrows.

@Test
public void delayWithFlowableSubscriptionThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    final PublishProcessor<Integer> delay = PublishProcessor.create();
    Supplier<Flowable<Integer>> subFunc = new Supplier<Flowable<Integer>>() {

        @Override
        public Flowable<Integer> get() {
            return delay;
        }
    };
    Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {

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

Example 19 with Supplier

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

the class FlowableBufferTest method timedSkipCancelWhenSecondBuffer.

@Test
public void timedSkipCancelWhenSecondBuffer() {
    TestScheduler sch = new TestScheduler();
    final TestSubscriber<List<Integer>> ts = new TestSubscriber<>();
    BufferSkipBoundedSubscriber<Integer, List<Integer>> sub = new BufferSkipBoundedSubscriber<>(ts, new Supplier<List<Integer>>() {

        int calls;

        @Override
        public List<Integer> get() throws Exception {
            if (++calls == 2) {
                ts.cancel();
            }
            return new ArrayList<>();
        }
    }, 1, 1, TimeUnit.SECONDS, sch.createWorker());
    sub.onSubscribe(new BooleanSubscription());
    sub.run();
    assertTrue(ts.isCancelled());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) IOException(java.io.IOException)

Example 20 with Supplier

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

the class FlowableDelayTest method delayWithFlowableSubscriptionFunctionThrows.

@Test
public void delayWithFlowableSubscriptionFunctionThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    final PublishProcessor<Integer> delay = PublishProcessor.create();
    Supplier<Flowable<Integer>> subFunc = new Supplier<Flowable<Integer>>() {

        @Override
        public Flowable<Integer> get() {
            throw new TestException();
        }
    };
    Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {

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

Aggregations

Test (org.junit.Test)37 TestException (io.reactivex.rxjava3.exceptions.TestException)33 Observable (io.reactivex.rxjava3.core.Observable)13 IOException (java.io.IOException)9 InOrder (org.mockito.InOrder)8 java.util (java.util)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 Supplier (io.reactivex.rxjava3.functions.Supplier)5 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)5 TestObserver (io.reactivex.rxjava3.observers.TestObserver)5 Observer (io.reactivex.rxjava3.core.Observer)4 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)4 ImmutableList (com.google.common.collect.ImmutableList)3 io.reactivex.rxjava3.processors (io.reactivex.rxjava3.processors)3 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)3 java.util.function (java.util.function)3 java.util.stream (java.util.stream)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 SQLUtils (com.alibaba.druid.sql.SQLUtils)2