// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
//   private Throwable cause;
//   private T result;
// 
//   public DefaultAsyncResult(Throwable cause, T result) {
//     this.cause = cause;
//     this.result = result;
//   }
// 
//   public static <T> AsyncResult<T> succeed(T result) {
//     return new DefaultAsyncResult<>(null, result);
//   }
// 
//   public static AsyncResult<Void> succeed() {
//     return succeed(null);
//   }
// 
//   public static <T> AsyncResult<T> fail(Throwable cause) {
//     if (cause == null) {
//       throw new IllegalArgumentException("cause argument cannot be null");
//     }
// 
//     return new DefaultAsyncResult<>(cause, null);
//   }
// 
//   public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
//     return fail(result.cause());
//   }
// 
//   @Override
//   public T result() {
//     return result;
//   }
// 
//   @Override
//   public Throwable cause() {
//     return cause;
//   }
// 
//   @Override
//   public boolean succeeded() {
//     return cause == null;
//   }
// 
//   @Override
//   public boolean failed() {
//     return cause != null;
//   }
// }


import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;
package org.simondean.vertx.async.unit.fakes;


public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
  private final int successCount;
  private final R result;
  private final Throwable cause;

  public FakeFailingAsyncFunction(Throwable cause) {
    this(0, null, cause);
  }

  public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
    this.successCount = successCount;
    this.result = result;
    this.cause = cause;
  }

  @Override
  public void accept(T value, AsyncResultHandler<R> handler) {
    addConsumedValue(value);
    incrementRunCount();

    if (runCount() > successCount) {
// Path: src/main/java/org/simondean/vertx/async/DefaultAsyncResult.java
// public class DefaultAsyncResult<T> implements AsyncResult<T> {
//   private Throwable cause;
//   private T result;
// 
//   public DefaultAsyncResult(Throwable cause, T result) {
//     this.cause = cause;
//     this.result = result;
//   }
// 
//   public static <T> AsyncResult<T> succeed(T result) {
//     return new DefaultAsyncResult<>(null, result);
//   }
// 
//   public static AsyncResult<Void> succeed() {
//     return succeed(null);
//   }
// 
//   public static <T> AsyncResult<T> fail(Throwable cause) {
//     if (cause == null) {
//       throw new IllegalArgumentException("cause argument cannot be null");
//     }
// 
//     return new DefaultAsyncResult<>(cause, null);
//   }
// 
//   public static <T> AsyncResult<T> fail(AsyncResult<?> result) {
//     return fail(result.cause());
//   }
// 
//   @Override
//   public T result() {
//     return result;
//   }
// 
//   @Override
//   public Throwable cause() {
//     return cause;
//   }
// 
//   @Override
//   public boolean succeeded() {
//     return cause == null;
//   }
// 
//   @Override
//   public boolean failed() {
//     return cause != null;
//   }
// }


// Path: src/test/java/org/simondean/vertx/async/unit/fakes/FakeFailingAsyncFunction.java
import org.simondean.vertx.async.DefaultAsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.impl.DefaultFutureResult;

package org.simondean.vertx.async.unit.fakes;


public class FakeFailingAsyncFunction<T, R> extends FakeAsyncFunction<T, R> {
  private final int successCount;
  private final R result;
  private final Throwable cause;

  public FakeFailingAsyncFunction(Throwable cause) {
    this(0, null, cause);
  }

  public FakeFailingAsyncFunction(int successCount, R result, Throwable cause) {
    this.successCount = successCount;
    this.result = result;
    this.cause = cause;
  }

  @Override
  public void accept(T value, AsyncResultHandler<R> handler) {
    addConsumedValue(value);
    incrementRunCount();

    if (runCount() > successCount) {
      handler.handle(DefaultAsyncResult.fail(cause));