### Question:
JdkFlowAdapters { public static <T> Publisher<T> fromFlowPublisher(java.util.concurrent.Flow.Publisher<T> source) { return new FlowToStPublisher<>(source); } private  JdkFlowAdapters(); static Publisher<T> fromFlowPublisher(java.util.concurrent.Flow.Publisher<T> source); static java.util.concurrent.Flow.Publisher<T> toFlowPublisher(Publisher<T> publisher); static java.util.concurrent.Flow.Publisher<T> toFlowPublisher(PublisherSource<T> source);  }### Answer:
@Test public void fromFlowSuccess() throws Exception { Publisher<Integer> flowPublisher = newMockFlowPublisher((subscriber, __) -> { subscriber.onNext(1); subscriber.onComplete(); }); Integer result = fromFlowPublisher(flowPublisher).firstOrElse(() -> null).toFuture().get(); assertThat("Unexpected result", result, is(1)); }
@Test public void fromFlowError() throws Exception { Publisher<Integer> flowPublisher = newMockFlowPublisher((subscriber, __) -> subscriber.onError(DELIBERATE_EXCEPTION)); Future<Integer> future = fromFlowPublisher(flowPublisher).firstOrElse(() -> null).toFuture(); expectedException.expect(instanceOf(ExecutionException.class)); expectedException.expectCause(sameInstance(DELIBERATE_EXCEPTION)); future.get(); }
@Test public void fromFlowCancel() { AtomicReference<Subscription> receivedSubscription = new AtomicReference<>(); Publisher<Integer> flowPublisher = newMockFlowPublisher((__, subscription) -> receivedSubscription.set(subscription)); fromFlowPublisher(flowPublisher).firstOrElse(() -> null).toFuture().cancel(true); Subscription subscription = receivedSubscription.get(); assertThat("Subscription not received.", subscription, is(notNullValue())); verify(subscription).cancel(); }