// Path: src/main/java/io/dazraf/vertx/futures/Futures.java
// static <T> Futures<T> when(Future<T> future) {
//   return FuturesImpl.when(future);
// }
// 
// Path: src/main/java/io/dazraf/vertx/futures/processors/CallProcessor.java
// static <T, R> CallProcessor<T, R> call(Supplier<Future<R>> supplier) {
//   return call(result -> supplier.get());
// }
// 
// Path: src/main/java/io/dazraf/vertx/futures/processors/MapProcessor.java
// static <T, R> MapProcessor<T, R> map(Function<T, R> function) {
//   return mapOnResponse(future -> {
//     if (future.succeeded()) {
//       return function.apply(future.result());
//     } else {
//       throw new WrappedException(future.cause());
//     }
//   });
// }
// 
// Path: src/main/java/io/dazraf/vertx/futures/processors/RunProcessor.java
// static <T> RunProcessor<T> runOnFail(Consumer<Throwable> consumer) {
//   return runOnResponse(failure(consumer));
// }
// 
// Path: src/main/java/io/dazraf/vertx/futures/processors/RunProcessor.java
// static <T> RunProcessor<T> run(Runnable runnable) {
//   return runOnResponse(success(runnable));
// }


import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import io.vertx.core.Future;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.RunTestOnContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import static io.dazraf.vertx.futures.Futures.when;
import static io.dazraf.vertx.futures.processors.CallProcessor.call;
import static io.dazraf.vertx.futures.processors.MapProcessor.map;
import static io.dazraf.vertx.futures.processors.RunProcessor.runOnFail;
import static io.dazraf.vertx.futures.processors.RunProcessor.run;
import static io.vertx.core.Future.failedFuture;
import static io.vertx.core.Future.future;
import static io.vertx.core.Future.succeededFuture;
        .then(run(async::complete))
        .then(runOnFail(context::fail));
    vertxContext.vertx().setTimer(10, id -> future.complete(MSG));
  }

  @Test
  public void testSimpleFailure(TestContext context) {
    Async async = context.async();
    when(failedFuture(MSG))
        .then(run(() -> context.fail("should have failed")))
        .then(runOnFail(err -> context.assertEquals(MSG, err.getMessage())))
        .then(runOnFail(err -> async.complete()));
  }

  @Test
  public void testSimpleAsyncFailure(TestContext context) {
    Async async = context.async();
    String MSG = "error";
    Future<String> future = future();
    when(future)
        .then(run(() -> context.fail("should have failed")))
        .then(runOnFail((err -> context.assertEquals(MSG, err.getMessage()))))
        .then(runOnFail(err -> async.complete()));
    vertxContext.vertx().setTimer(10, id -> future.fail(MSG));
  }

  @Test
  public void test2SuccessfulFlow(TestContext context) {
    Async async = context.async();
    when(futureMessage(), futureNumber())
// Path: src/main/java/io/dazraf/vertx/futures/Futures.java
// static <T> Futures<T> when(Future<T> future) {
//   return FuturesImpl.when(future);
// }
// 
// Path: src/main/java/io/dazraf/vertx/futures/processors/CallProcessor.java
// static <T, R> CallProcessor<T, R> call(Supplier<Future<R>> supplier) {
//   return call(result -> supplier.get());
// }
// 
// Path: src/main/java/io/dazraf/vertx/futures/processors/MapProcessor.java
// static <T, R> MapProcessor<T, R> map(Function<T, R> function) {
//   return mapOnResponse(future -> {
//     if (future.succeeded()) {
//       return function.apply(future.result());
//     } else {
//       throw new WrappedException(future.cause());
//     }
//   });
// }
// 
// Path: src/main/java/io/dazraf/vertx/futures/processors/RunProcessor.java
// static <T> RunProcessor<T> runOnFail(Consumer<Throwable> consumer) {
//   return runOnResponse(failure(consumer));
// }
// 
// Path: src/main/java/io/dazraf/vertx/futures/processors/RunProcessor.java
// static <T> RunProcessor<T> run(Runnable runnable) {
//   return runOnResponse(success(runnable));
// }


// Path: src/test/java/io/dazraf/vertx/futures/processors/RunProcessorTest.java
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import io.vertx.core.Future;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.RunTestOnContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import static io.dazraf.vertx.futures.Futures.when;
import static io.dazraf.vertx.futures.processors.CallProcessor.call;
import static io.dazraf.vertx.futures.processors.MapProcessor.map;
import static io.dazraf.vertx.futures.processors.RunProcessor.runOnFail;
import static io.dazraf.vertx.futures.processors.RunProcessor.run;
import static io.vertx.core.Future.failedFuture;
import static io.vertx.core.Future.future;
import static io.vertx.core.Future.succeededFuture;

        .then(run(async::complete))
        .then(runOnFail(context::fail));
    vertxContext.vertx().setTimer(10, id -> future.complete(MSG));
  }

  @Test
  public void testSimpleFailure(TestContext context) {
    Async async = context.async();
    when(failedFuture(MSG))
        .then(run(() -> context.fail("should have failed")))
        .then(runOnFail(err -> context.assertEquals(MSG, err.getMessage())))
        .then(runOnFail(err -> async.complete()));
  }

  @Test
  public void testSimpleAsyncFailure(TestContext context) {
    Async async = context.async();
    String MSG = "error";
    Future<String> future = future();
    when(future)
        .then(run(() -> context.fail("should have failed")))
        .then(runOnFail((err -> context.assertEquals(MSG, err.getMessage()))))
        .then(runOnFail(err -> async.complete()));
    vertxContext.vertx().setTimer(10, id -> future.fail(MSG));
  }

  @Test
  public void test2SuccessfulFlow(TestContext context) {
    Async async = context.async();
    when(futureMessage(), futureNumber())
        .then(map((msg, number) -> msg + number))