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());
}
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());
}
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();
}
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());
}
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();
}
Aggregations