// Path: src/test/java/com/spotify/trickle/Util.java
// static Matcher<Throwable> hasAncestor(final Throwable expected) {
//   return new TypeSafeMatcher<Throwable>() {
//     @Override
//     protected boolean matchesSafely(Throwable item) {
//       for (Throwable cause = item ; cause != null ; cause = cause.getCause()) {
//         if (cause.equals(expected)) {
//           return true;
//         }
//       }
// 
//       return false;
//     }
// 
//     @Override
//     public void describeTo(Description description) {
//       description.appendText("with parent cause " + expected);
//     }
//   };
// }


import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import org.junit.Before;
import org.junit.Test;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import static com.google.common.util.concurrent.Futures.immediateFuture;
import static com.spotify.trickle.Util.hasAncestor;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
    currentCallInfo = new CallInfo(currentNodeInfo, NO_PARAMS);

    fallback = new NodeExecutionFallback<String>(graphBuilder, currentCall, traverseState);
  }

  @Test
  public void shouldNotWrapGraphExecutionException() throws Exception {
    Throwable expected = new GraphExecutionException(null, currentCallInfo, NO_CALLS);

    ListenableFuture<String> future = fallback.create(expected);

    try {
      future.get();
      fail("expected an exception");
    } catch (ExecutionException e) {
      assertThat(e.getCause(), equalTo(expected));
    }
  }

  @Test
  public void shouldWrapGeneralException() throws Exception {
    Throwable expected = new RuntimeException("expected");

    ListenableFuture<String> future = fallback.create(expected);

    try {
      future.get();
      fail("expected an exception");
    } catch (ExecutionException e) {
      assertThat(e.getCause(), not(equalTo(expected)));
// Path: src/test/java/com/spotify/trickle/Util.java
// static Matcher<Throwable> hasAncestor(final Throwable expected) {
//   return new TypeSafeMatcher<Throwable>() {
//     @Override
//     protected boolean matchesSafely(Throwable item) {
//       for (Throwable cause = item ; cause != null ; cause = cause.getCause()) {
//         if (cause.equals(expected)) {
//           return true;
//         }
//       }
// 
//       return false;
//     }
// 
//     @Override
//     public void describeTo(Description description) {
//       description.appendText("with parent cause " + expected);
//     }
//   };
// }


// Path: src/test/java/com/spotify/trickle/NodeExecutionFallbackTest.java
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import org.junit.Before;
import org.junit.Test;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import static com.google.common.util.concurrent.Futures.immediateFuture;
import static com.spotify.trickle.Util.hasAncestor;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

    currentCallInfo = new CallInfo(currentNodeInfo, NO_PARAMS);

    fallback = new NodeExecutionFallback<String>(graphBuilder, currentCall, traverseState);
  }

  @Test
  public void shouldNotWrapGraphExecutionException() throws Exception {
    Throwable expected = new GraphExecutionException(null, currentCallInfo, NO_CALLS);

    ListenableFuture<String> future = fallback.create(expected);

    try {
      future.get();
      fail("expected an exception");
    } catch (ExecutionException e) {
      assertThat(e.getCause(), equalTo(expected));
    }
  }

  @Test
  public void shouldWrapGeneralException() throws Exception {
    Throwable expected = new RuntimeException("expected");

    ListenableFuture<String> future = fallback.create(expected);

    try {
      future.get();
      fail("expected an exception");
    } catch (ExecutionException e) {
      assertThat(e.getCause(), not(equalTo(expected)));
      assertThat(e, hasAncestor(expected));