package io.dazraf.vertx.futures;

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.ifFailedRun;
import static io.dazraf.vertx.futures.processors.RunProcessor.run;
import static io.vertx.core.Future.succeededFuture;
import static org.slf4j.LoggerFactory.getLogger;

@RunWith(VertxUnitRunner.class)
public class FuturesTest {

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

  public static final int ID = 1;
  @ClassRule
  public static RunTestOnContext context = new RunTestOnContext();

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

  private Future<Integer> getId() {
    return succeededFuture(ID);
  }


  private Future<String> getName(int id) {
    return succeededFuture("name-" + id);
  }

  private Future<Integer> getAge(int id) {
    return succeededFuture(42);
  }

  private Future<String> composeMessage(String name, int age) {
    return succeededFuture("Hi " + name + " you are " + age + " years old");
  }
}

@@ -27,16 +27,75 @@
 tures;%0A%0A
+import org.hamcrest.CoreMatchers;%0Aimport org.junit.Assert;%0A
 import o
@@ -114,16 +114,16 @@
 ssRule;%0A
-
 import o
@@ -634,24 +634,102 @@
 ededFuture;%0A
+import static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.*;%0A
 import stati
@@ -892,29 +892,30 @@
 class);%0A%0A  p
-ublic
+rivate
  static fina
@@ -928,16 +928,73 @@
 ID = 1;%0A
+  private  static final String FAILURE_MSG = %22Failure!%22;%0A
   @Class
@@ -1092,19 +1092,43 @@
 oid 
-generalTest
+test_1then2then1_happypath_succeeds
 () %7B
@@ -1308,24 +1308,24 @@
 o(result)))%0A
-
         .the
@@ -1381,32 +1381,711 @@
  cause)));%0A  %7D%0A%0A
+  @Test%0A  public void test_unresolvedFutureImpl_canBeFailedWithString() %7B%0A    Futures%3CInteger%3E future = new FuturesImpl%3C%3E(null);%0A    future.fail(FAILURE_MSG);%0A    assertTrue(future.failed());%0A    assertThat(future.cause().getMessage(), is(FAILURE_MSG));%0A  %7D%0A%0A  @Test%0A  public void test_canComplete() %7B%0A    Futures%3CInteger%3E future = new FuturesImpl%3C%3E(null);%0A    assertFalse(future.isComplete());%0A    future.complete();%0A    assertTrue(future.isComplete() && future.result() == null);%0A  %7D%0A%0A  @Test%0A  public void test_whenOfFutures_returnsSame() %7B%0A    Future%3CString%3E f1 = Futures.when(succeededFuture(%22hello%22));%0A    Future%3CString%3E f2 = Futures.when(f1);%0A    assertSame(f1, f2);%0A  %7D%0A%0A
   private Future

increase coverage of FuturesImpl