### Question:
OnErrorStageFactory implements ProcessingStageFactory<Stage.OnError> { @SuppressWarnings("unchecked") @Override public <I, O> ProcessingStage<I, O> create(Engine engine, Stage.OnError stage) { Consumer<Throwable> consumer = Objects.requireNonNull(stage).getConsumer(); Objects.requireNonNull(consumer); return source -> (Multi<O>) source.onFailure().invoke(consumer); }  @SuppressWarnings("unchecked") @Override ProcessingStage<I, O> create(Engine engine, Stage.OnError stage);  }### Answer:
@Test public void create() throws ExecutionException, InterruptedException { Multi<Integer> publisher = Multi.createFrom().items(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .emitOn(executor); AtomicReference<Throwable> error = new AtomicReference<>(); ReactiveStreams.fromPublisher(publisher) .filter(i -> i < 4) .map(this::squareOrFailed) .onError(error::set) .map(this::asString) .toList() .run().toCompletableFuture().exceptionally(x -> Collections.emptyList()).get(); assertThat(error.get()).hasMessage("failed"); }
@Test public void createWithoutStage() { assertThrows(NullPointerException.class, () -> factory.create(null, null)); }
@Test public void createWithoutFunction() { assertThrows(NullPointerException.class, () -> factory.create(null, () -> null)); }