### Question:
UniOnItemTransformToMulti extends AbstractMulti<O> { @Override public void subscribe(MultiSubscriber<? super O> subscriber) { if (subscriber == null) { throw new NullPointerException("The subscriber must not be `null`"); } AbstractUni.subscribe(upstream, new FlatMapPublisherSubscriber<>(subscriber, mapper)); } UniOnItemTransformToMulti(Uni<I> upstream, Function<? super I, ? extends Publisher<? extends O>> mapper); @Override void subscribe(MultiSubscriber<? super O> subscriber);  }### Answer:
@Test public void testTransformToMultiWithItem() { Uni.createFrom().item(1) .onItem().transformToMulti(i -> Multi.createFrom().range(i, 5)) .subscribe().withSubscriber(AssertSubscriber.create(10)) .await() .assertCompletedSuccessfully() .assertReceived(1, 2, 3, 4); }
@Test @SuppressWarnings("deprecation") public void testTransformToMultiWithItemDeprecated() { Uni.createFrom().item(1) .onItem().produceMulti(i -> Multi.createFrom().range(i, 5)) .subscribe().withSubscriber(AssertSubscriber.create(10)) .await() .assertCompletedSuccessfully() .assertReceived(1, 2, 3, 4); }
@Test public void testTransformToMultiWithNull() { Uni.createFrom().voidItem() .onItem().transformToMulti(x -> Multi.createFrom().range(1, 5)) .subscribe().withSubscriber(AssertSubscriber.create(10)) .await() .assertCompletedSuccessfully() .assertReceived(1, 2, 3, 4); }
@Test public void testTransformToMultiWithFailure() { Uni.createFrom().<Integer> failure(new IOException("boom")) .onItem().transformToMulti(x -> Multi.createFrom().range(1, 5)) .subscribe().withSubscriber(AssertSubscriber.create(10)) .await() .assertHasFailedWith(IOException.class, "boom") .assertHasNotReceivedAnyItem(); }
@Test public void testTransformToMultiWithExceptionThrownByMapper() { Uni.createFrom().item(1) .onItem().transformToMulti(x -> { throw new IllegalStateException("boom"); }) .subscribe().withSubscriber(AssertSubscriber.create(10)) .await() .assertHasFailedWith(IllegalStateException.class, "boom") .assertHasNotReceivedAnyItem(); }
@Test public void testTransformToMultiWithNullReturnedByMapper() { Uni.createFrom().item(1) .onItem().transformToMulti(x -> null) .subscribe().withSubscriber(AssertSubscriber.create(10)) .await() .assertHasFailedWith(NullPointerException.class, "") .assertHasNotReceivedAnyItem(); }
@Test public void testTransformToMultiWithNullReturnedByMapperWithCancellationDuringTheUniResolution() { final AtomicBoolean called = new AtomicBoolean(); Uni.createFrom().<Integer> nothing() .onCancellation().invoke(() -> called.set(true)) .onItem().transformToMulti(x -> Multi.createFrom().range(x, 10)) .subscribe().withSubscriber(AssertSubscriber.create(10)) .assertNotTerminated() .assertHasNotReceivedAnyItem() .run(() -> assertThat(called).isFalse()) .cancel() .run(() -> assertThat(called).isTrue()) .assertNotTerminated(); }
@Test public void testTransformToMultiWithNullReturnedByMapperWithCancellationDuringTheMultiEmissions() { final AtomicBoolean called = new AtomicBoolean(); final AtomicBoolean calledUni = new AtomicBoolean(); Uni.createFrom().item(1) .onCancellation().invoke(() -> calledUni.set(true)) .onItem().transformToMulti(i -> Multi.createFrom().nothing() .on().cancellation(() -> called.set(true))) .subscribe().withSubscriber(AssertSubscriber.create(10)) .assertNotTerminated() .assertHasNotReceivedAnyItem() .run(() -> assertThat(called).isFalse()) .cancel() .run(() -> assertThat(called).isTrue()) .run(() -> assertThat(calledUni).isFalse()) .assertNotTerminated(); }