use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class ObservableCollectWithCollectorTest method collectorAccumulatorDropSignalsToObservable.
@Test
public void collectorAccumulatorDropSignalsToObservable() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Observable<Integer> source = new Observable<Integer>() {
@Override
protected void subscribeActual(Observer<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onNext(1);
observer.onNext(2);
observer.onError(new IOException());
observer.onComplete();
}
};
source.collect(new Collector<Integer, Integer, Integer>() {
@Override
public Supplier<Integer> supplier() {
return () -> 1;
}
@Override
public BiConsumer<Integer, Integer> accumulator() {
return (a, b) -> {
throw new TestException();
};
}
@Override
public BinaryOperator<Integer> combiner() {
return (a, b) -> a + b;
}
@Override
public Function<Integer, Integer> finisher() {
return a -> a;
}
@Override
public Set<Characteristics> characteristics() {
return Collections.emptySet();
}
}).toObservable().test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
});
}
use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class FlowableCollectWithCollectorTest method collectorAccumulatorDropSignals.
@Test
public void collectorAccumulatorDropSignals() throws Throwable {
TestHelper.withErrorTracking(errors -> {
Flowable<Integer> source = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onError(new IOException());
s.onComplete();
}
};
source.collect(new Collector<Integer, Integer, Integer>() {
@Override
public Supplier<Integer> supplier() {
return () -> 1;
}
@Override
public BiConsumer<Integer, Integer> accumulator() {
return (a, b) -> {
throw new TestException();
};
}
@Override
public BinaryOperator<Integer> combiner() {
return (a, b) -> a + b;
}
@Override
public Function<Integer, Integer> finisher() {
return a -> a;
}
@Override
public Set<Characteristics> characteristics() {
return Collections.emptySet();
}
}).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
});
}
use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class SingleFromSupplierTest method fromSupplierTwice.
@Test
public void fromSupplierTwice() {
final AtomicInteger atomicInteger = new AtomicInteger();
Supplier<Integer> supplier = new Supplier<Integer>() {
@Override
public Integer get() throws Exception {
return atomicInteger.incrementAndGet();
}
};
Single.fromSupplier(supplier).test().assertResult(1);
assertEquals(1, atomicInteger.get());
Single.fromSupplier(supplier).test().assertResult(2);
assertEquals(2, atomicInteger.get());
}
use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class RxJavaPluginsTest method clearIsPassthrough.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void clearIsPassthrough() {
try {
RxJavaPlugins.reset();
assertNull(RxJavaPlugins.onAssembly((Observable) null));
assertNull(RxJavaPlugins.onAssembly((ConnectableObservable) null));
assertNull(RxJavaPlugins.onAssembly((Flowable) null));
assertNull(RxJavaPlugins.onAssembly((ConnectableFlowable) null));
Observable oos = new Observable() {
@Override
public void subscribeActual(Observer t) {
}
};
Flowable fos = new Flowable() {
@Override
public void subscribeActual(Subscriber t) {
}
};
assertSame(oos, RxJavaPlugins.onAssembly(oos));
assertSame(fos, RxJavaPlugins.onAssembly(fos));
assertNull(RxJavaPlugins.onAssembly((Single) null));
Single sos = new Single() {
@Override
public void subscribeActual(SingleObserver t) {
}
};
assertSame(sos, RxJavaPlugins.onAssembly(sos));
assertNull(RxJavaPlugins.onAssembly((Completable) null));
Completable cos = new Completable() {
@Override
public void subscribeActual(CompletableObserver t) {
}
};
assertSame(cos, RxJavaPlugins.onAssembly(cos));
assertNull(RxJavaPlugins.onAssembly((Maybe) null));
Maybe myb = new Maybe() {
@Override
public void subscribeActual(MaybeObserver t) {
}
};
assertSame(myb, RxJavaPlugins.onAssembly(myb));
Runnable action = Functions.EMPTY_RUNNABLE;
assertSame(action, RxJavaPlugins.onSchedule(action));
class AllSubscriber implements Subscriber, Observer, SingleObserver, CompletableObserver, MaybeObserver {
@Override
public void onSuccess(Object value) {
}
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onSubscribe(Subscription s) {
}
@Override
public void onNext(Object t) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
}
}
AllSubscriber all = new AllSubscriber();
Subscriber[] allArray = { all };
assertNull(RxJavaPlugins.onSubscribe(Observable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Observable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Flowable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Flowable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Single.just(1), null));
assertSame(all, RxJavaPlugins.onSubscribe(Single.just(1), all));
assertNull(RxJavaPlugins.onSubscribe(Completable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Completable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Maybe.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Maybe.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Flowable.never().parallel(), null));
assertSame(allArray, RxJavaPlugins.onSubscribe(Flowable.never().parallel(), allArray));
final Scheduler s = ImmediateThinScheduler.INSTANCE;
Supplier<Scheduler> c = new Supplier<Scheduler>() {
@Override
public Scheduler get() throws Exception {
return s;
}
};
assertSame(s, RxJavaPlugins.onComputationScheduler(s));
assertSame(s, RxJavaPlugins.onIoScheduler(s));
assertSame(s, RxJavaPlugins.onNewThreadScheduler(s));
assertSame(s, RxJavaPlugins.onSingleScheduler(s));
assertSame(s, RxJavaPlugins.initComputationScheduler(c));
assertSame(s, RxJavaPlugins.initIoScheduler(c));
assertSame(s, RxJavaPlugins.initNewThreadScheduler(c));
assertSame(s, RxJavaPlugins.initSingleScheduler(c));
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class ObservableDeferTest method deferFunctionThrows.
@Test
public void deferFunctionThrows() throws Throwable {
Supplier<Observable<String>> factory = mock(Supplier.class);
when(factory.get()).thenThrow(new TestException());
Observable<String> result = Observable.defer(factory);
Observer<String> o = TestHelper.mockObserver();
result.subscribe(o);
verify(o).onError(any(TestException.class));
verify(o, never()).onNext(any(String.class));
verify(o, never()).onComplete();
}
Aggregations