// Path: src/test/java/com/contentful/java/cda/BaseTest.java
// public class BaseTest {
//   public static final String DEFAULT_TOKEN = "test_token";
//   public static final String DEFAULT_SPACE = "test_space";
//   public static final String STAGING_ENVIRONMENT = "staging";
// 
//   CDAClient client;
// 
//   MockWebServer server;
// 
//   List<TestResponse> responseQueue;
// 
//   @Rule public EnqueueResponseRule enqueueResponse = new EnqueueResponseRule();
// 
//   @Before public void setUp() throws IOException {
//     LogManager.getLogManager().reset();
//     server = createServer();
//     server.start();
// 
//     client = createClient();
// 
//     if (responseQueue != null) {
//       for (TestResponse response : responseQueue) {
//         enqueue(response);
//       }
//     }
//   }
// 
//   @After public void tearDown() throws IOException {
//     server.shutdown();
//   }
// 
//   protected CDAClient createClient() {
//     return createBuilder()
//         .build();
//   }
// 
//   protected CDAClient createPreviewClient() {
//     return createBuilder()
//         .preview()
//         .setEndpoint(serverUrl())
//         .build();
//   }
// 
//   protected CDAClient.Builder createBuilder() {
//     return CDAClient.builder()
//         .setSpace(DEFAULT_SPACE)
//         .setToken(DEFAULT_TOKEN)
//         .setEndpoint(serverUrl());
//   }
// 
//   protected String serverUrl() {
//     return "http://" + server.getHostName() + ":" + server.getPort();
//   }
// 
//   protected MockWebServer createServer() {
//     return new MockWebServer();
//   }
// 
//   protected void enqueue(TestResponse response) throws IOException {
//     URL resource = getClass().getClassLoader().getResource(response.getFileName());
//     checkNotNull(resource, "File not found: " + response.getFileName());
//     final MockResponse mock = new MockResponse()
//         .setResponseCode(response.getCode())
//         .setBody(readFileToString(new File(resource.getFile()), defaultCharset()));
// 
//     if (response.headers().size() > 0) {
//       mock.setHeaders(response.headers());
//     }
// 
//     server.enqueue(mock);
//   }
// 
//   public BaseTest setResponseQueue(List<TestResponse> responseQueue) {
//     this.responseQueue = responseQueue;
//     return this;
//   }
// 
//   protected <T extends CDAResource> T assertCallback(TestCallback<T> callback) {
//     assertThat(callback.error()).isNull();
//     assertThat(callback.result()).isNotNull();
//     return callback.result();
//   }
// }


import com.contentful.java.cda.BaseTest;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
package com.contentful.java.cda.lib;




public class EnqueueResponseRule implements MethodRule {
  @Override public Statement apply(Statement statement, FrameworkMethod method, Object o) {
    Enqueue enqueue = method.getAnnotation(Enqueue.class);
    if (enqueue != null) {
      if (!(o instanceof BaseTest)) {
        throw new RuntimeException("Test class must extend "
            + BaseTest.class.getName()
            + "when using @"
            + Enqueue.class.getSimpleName());
      }
      List<TestResponse> responses = new ArrayList<>(enqueueToTestResponse(enqueue));
// Path: src/test/java/com/contentful/java/cda/BaseTest.java
// public class BaseTest {
//   public static final String DEFAULT_TOKEN = "test_token";
//   public static final String DEFAULT_SPACE = "test_space";
//   public static final String STAGING_ENVIRONMENT = "staging";
// 
//   CDAClient client;
// 
//   MockWebServer server;
// 
//   List<TestResponse> responseQueue;
// 
//   @Rule public EnqueueResponseRule enqueueResponse = new EnqueueResponseRule();
// 
//   @Before public void setUp() throws IOException {
//     LogManager.getLogManager().reset();
//     server = createServer();
//     server.start();
// 
//     client = createClient();
// 
//     if (responseQueue != null) {
//       for (TestResponse response : responseQueue) {
//         enqueue(response);
//       }
//     }
//   }
// 
//   @After public void tearDown() throws IOException {
//     server.shutdown();
//   }
// 
//   protected CDAClient createClient() {
//     return createBuilder()
//         .build();
//   }
// 
//   protected CDAClient createPreviewClient() {
//     return createBuilder()
//         .preview()
//         .setEndpoint(serverUrl())
//         .build();
//   }
// 
//   protected CDAClient.Builder createBuilder() {
//     return CDAClient.builder()
//         .setSpace(DEFAULT_SPACE)
//         .setToken(DEFAULT_TOKEN)
//         .setEndpoint(serverUrl());
//   }
// 
//   protected String serverUrl() {
//     return "http://" + server.getHostName() + ":" + server.getPort();
//   }
// 
//   protected MockWebServer createServer() {
//     return new MockWebServer();
//   }
// 
//   protected void enqueue(TestResponse response) throws IOException {
//     URL resource = getClass().getClassLoader().getResource(response.getFileName());
//     checkNotNull(resource, "File not found: " + response.getFileName());
//     final MockResponse mock = new MockResponse()
//         .setResponseCode(response.getCode())
//         .setBody(readFileToString(new File(resource.getFile()), defaultCharset()));
// 
//     if (response.headers().size() > 0) {
//       mock.setHeaders(response.headers());
//     }
// 
//     server.enqueue(mock);
//   }
// 
//   public BaseTest setResponseQueue(List<TestResponse> responseQueue) {
//     this.responseQueue = responseQueue;
//     return this;
//   }
// 
//   protected <T extends CDAResource> T assertCallback(TestCallback<T> callback) {
//     assertThat(callback.error()).isNull();
//     assertThat(callback.result()).isNotNull();
//     return callback.result();
//   }
// }


// Path: src/test/java/com/contentful/java/cda/lib/EnqueueResponseRule.java
import com.contentful.java.cda.BaseTest;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

package com.contentful.java.cda.lib;




public class EnqueueResponseRule implements MethodRule {
  @Override public Statement apply(Statement statement, FrameworkMethod method, Object o) {
    Enqueue enqueue = method.getAnnotation(Enqueue.class);
    if (enqueue != null) {
      if (!(o instanceof BaseTest)) {
        throw new RuntimeException("Test class must extend "
            + BaseTest.class.getName()
            + "when using @"
            + Enqueue.class.getSimpleName());
      }
      List<TestResponse> responses = new ArrayList<>(enqueueToTestResponse(enqueue));
      ((BaseTest) o).setResponseQueue(responses);