// 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/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 org.slf4j.Logger;
import io.vertx.core.Future;
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.RunProcessor.runOnFail;
import static io.dazraf.vertx.futures.processors.RunProcessor.run;
import static io.vertx.core.Future.succeededFuture;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.slf4j.LoggerFactory.getLogger;
package io.dazraf.vertx.futures;




@RunWith(VertxUnitRunner.class)
public class FuturesTest {

  private static final Logger LOG = getLogger(FuturesTest.class);

  private static final int ID = 1;
  private  static final String FAILURE_MSG = "Failure!";
  @ClassRule
  public static RunTestOnContext context = new RunTestOnContext();

  @Test
  public void test_1then2then1_happypath_succeeds() {
    when(getId())
        .then(call(id -> when(getName(id), getAge(id))))
        .then(call((name, age) -> composeMessage(name, age)))
        .then(run(result -> LOG.info(result)))
        .then(runOnFail(cause -> LOG.error("error handler", cause)));
  }

  @Test
  public void test_unresolvedFutureImpl_canBeFailedWithString() {
    Futures<Integer> future = new FuturesImpl<>(null);
    future.fail(FAILURE_MSG);
    assertTrue(future.failed());
// 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/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/FuturesTest.java
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import io.vertx.core.Future;
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.RunProcessor.runOnFail;
import static io.dazraf.vertx.futures.processors.RunProcessor.run;
import static io.vertx.core.Future.succeededFuture;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.slf4j.LoggerFactory.getLogger;

package io.dazraf.vertx.futures;




@RunWith(VertxUnitRunner.class)
public class FuturesTest {

  private static final Logger LOG = getLogger(FuturesTest.class);

  private static final int ID = 1;
  private  static final String FAILURE_MSG = "Failure!";
  @ClassRule
  public static RunTestOnContext context = new RunTestOnContext();

  @Test
  public void test_1then2then1_happypath_succeeds() {
    when(getId())
        .then(call(id -> when(getName(id), getAge(id))))
        .then(call((name, age) -> composeMessage(name, age)))
        .then(run(result -> LOG.info(result)))
        .then(runOnFail(cause -> LOG.error("error handler", cause)));
  }

  @Test
  public void test_unresolvedFutureImpl_canBeFailedWithString() {
    Futures<Integer> future = new FuturesImpl<>(null);
    future.fail(FAILURE_MSG);
    assertTrue(future.failed());
    assertThat(future.cause().getMessage(), is(FAILURE_MSG));