### Question:
FutureResult { public <R> CompletableFuture<R> fold(Function<NonEmptyList<E>, R> e, Function<T, R> f) { return run.thenApply(r -> r.fold(e, f)); } private  FutureResult(final CompletableFuture<Result<E, T>> run); private  FutureResult(final Supplier<Result<E, T>> supplier); static FutureResult<E, T> ofCompletableFuture(final CompletableFuture<Result<E, T>> run); static FutureResult<E, T> ofFuture(final Future<T> run, final Function<Exception, E> f); static FutureResult<E, T> ofFutureResult(final Future<Result<E, T>> future, final Function<Exception, E> f); static FutureResult<E, T> ofResult(final Result<E, T> result); static FutureResult<E, T> ofSupplier(final Supplier<Result<E, T>> supplier); static FutureResult<E, T> of(final T t); @SafeVarargs static FutureResult<E, T> fail(final E error, final E... errors); static FutureResult<E, T> fail(final NonEmptyList<E> errors); Result<E, T> unsafePerform(final Function<Exception, E> f); Result<E, T> getOrElse(final Supplier<Result<E, T>> resultSupplier, final Function<Exception, E> f); CompletableFuture<Result<E, T>> future(); FutureResult<E, R> map(Function<T, R> f); FutureResult<F, T> errorMap(Function<E, F> f); CompletableFuture<R> fold(Function<NonEmptyList<E>, R> e, Function<T, R> f); FutureResult<E, R> flatMap(Function<T, FutureResult<E, R>> f);  }### Answer:
@Test void foldShouldMapIntValueToStringWhenFutureResultIsSuccess() { FutureResult<TestError, Integer> futureResult = asynchronousSuccess(futureResultReturnSignal, 10); triggerFutureResultReturnSignal(); assertDoesNotThrow(() -> { String actualResult = futureResult.fold(null, Object::toString).get(); assertThat(actualResult).isEqualTo("10"); }); }
@Test void foldShouldConcatenateErrorReasonsWhenFutureResultIsFailure() { FutureResult<TestError, Integer> futureResult = asynchronousFailure(futureResultReturnSignal, FAILURE_COMMAND_ERROR_1, FAILURE_COMMAND_ERROR_2); triggerFutureResultReturnSignal(); assertDoesNotThrow(() -> { List<TestError.Reason> actualResult = futureResult.fold(TO_ERROR_REASON_FUNC, null).get(); assertThat(actualResult).containsOnly(TestError.Reason.InternalError, TestError.Reason.UnexpectedErrorCode); }); }