use of io.reactivex.rxjava3.functions.Function in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerScheduleOnceUsesHook.
@Test
public void workerScheduleOnceUsesHook() {
final CountingRunnable newCounter = new CountingRunnable();
final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
@Override
public Runnable apply(Runnable runnable) {
runnableRef.set(runnable);
return newCounter;
}
});
Worker worker = scheduler.createWorker();
CountingRunnable counter = new CountingRunnable();
worker.schedule(counter);
// Verify our runnable was passed to the schedulers hook.
assertSame(counter, runnableRef.get());
runUiThreadTasks();
// Verify the scheduled runnable was the one returned from the hook.
assertEquals(1, newCounter.get());
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Function 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.Function 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.Function in project RxJava by ReactiveX.
the class SingleConcatMapCompletableTest method mapperThrows.
@Test
public void mapperThrows() {
final boolean[] b = { false };
Single.just(1).concatMapCompletable(new Function<Integer, Completable>() {
@Override
public Completable apply(Integer t) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
assertFalse(b[0]);
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class SingleFlatMapTest method mapperThrows.
@Test
public void mapperThrows() {
final boolean[] b = { false };
Single.just(1).flatMapCompletable(new Function<Integer, Completable>() {
@Override
public Completable apply(Integer t) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
assertFalse(b[0]);
}
Aggregations