// Path: src/test/java/com/gocardless/http/HttpTestUtil.java
// public static class DummyItem {
//     public String stringField;
//     public int intField;
// }
// 
// Path: src/test/java/com/gocardless/http/ListRequestTest.java
// static class DummyListRequest<S> extends ListRequest<S, DummyItem> {
//     private DummyListRequest(HttpClient httpClient,
//             ListRequestExecutor<S, DummyItem> executor) {
//         super(httpClient, executor);
//     }
// 
//     public DummyListRequest<S> withHeader(String headerName, String headerValue) {
//         this.addHeader(headerName, headerValue);
//         return this;
//     }
// 
//     @Override
//     protected ImmutableMap<String, Object> getQueryParams() {
//         return ImmutableMap.<String, Object>builder().putAll(super.getQueryParams())
//                 .put("id", "123").build();
//     }
// 
//     @Override
//     protected String getPathTemplate() {
//         return "/dummy";
//     }
// 
//     @Override
//     protected String getEnvelope() {
//         return "items";
//     }
// 
//     @Override
//     protected TypeToken<List<DummyItem>> getTypeToken() {
//         return new TypeToken<List<DummyItem>>() {};
//     }
// 
//     static DummyListRequest<ListResponse<DummyItem>> pageRequest(HttpClient httpClient) {
//         return new DummyListRequest<>(httpClient, ListRequest.<DummyItem>pagingExecutor());
//     }
// 
//     static DummyListRequest<Iterable<DummyItem>> iterableRequest(HttpClient httpClient) {
//         return new DummyListRequest<>(httpClient, ListRequest.<DummyItem>iteratingExecutor());
//     }
// }


import static org.assertj.core.api.Assertions.assertThat;
import com.gocardless.http.HttpTestUtil.DummyItem;
import com.gocardless.http.ListRequestTest.DummyListRequest;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
                ImmutableMap.of("Authorization", "Bearer token"));
        http.assertRequestMade("GET", "/dummy?after=ID123&limit=2&id=123",
                ImmutableMap.of("Authorization", "Bearer token"));
    }

    @Test
    public void shouldCopeWithEmptyLastPage() throws Exception {
        http.enqueueResponse(200, "fixtures/first-page.json");
        http.enqueueResponse(200, "fixtures/empty-page.json");
        DummyListRequest<Iterable<DummyItem>> request =
                DummyListRequest.iterableRequest(http.client());
        request.setLimit(2);
        Iterable<DummyItem> iterable = new PaginatingIterable<>(request, http.client());
        List<DummyItem> items = Lists.newArrayList(iterable);
        assertThat(items).hasSize(2);
        assertThat(items.get(0).stringField).isEqualTo("foo");
        assertThat(items.get(0).intField).isEqualTo(111);
        assertThat(items.get(1).stringField).isEqualTo("bar");
        assertThat(items.get(1).intField).isEqualTo(222);
        http.assertRequestMade("GET", "/dummy?limit=2&id=123",
                ImmutableMap.of("Authorization", "Bearer token"));
        http.assertRequestMade("GET", "/dummy?after=ID123&limit=2&id=123",
                ImmutableMap.of("Authorization", "Bearer token"));
    }

    @Test
    public void shouldRetryOnNetworkFailure() throws Exception {
        http.enqueueNetworkFailure();
        http.enqueueResponse(200, "fixtures/first-page.json");
        http.enqueueResponse(200, "fixtures/last-page.json");
// Path: src/test/java/com/gocardless/http/HttpTestUtil.java
// public static class DummyItem {
//     public String stringField;
//     public int intField;
// }
// 
// Path: src/test/java/com/gocardless/http/ListRequestTest.java
// static class DummyListRequest<S> extends ListRequest<S, DummyItem> {
//     private DummyListRequest(HttpClient httpClient,
//             ListRequestExecutor<S, DummyItem> executor) {
//         super(httpClient, executor);
//     }
// 
//     public DummyListRequest<S> withHeader(String headerName, String headerValue) {
//         this.addHeader(headerName, headerValue);
//         return this;
//     }
// 
//     @Override
//     protected ImmutableMap<String, Object> getQueryParams() {
//         return ImmutableMap.<String, Object>builder().putAll(super.getQueryParams())
//                 .put("id", "123").build();
//     }
// 
//     @Override
//     protected String getPathTemplate() {
//         return "/dummy";
//     }
// 
//     @Override
//     protected String getEnvelope() {
//         return "items";
//     }
// 
//     @Override
//     protected TypeToken<List<DummyItem>> getTypeToken() {
//         return new TypeToken<List<DummyItem>>() {};
//     }
// 
//     static DummyListRequest<ListResponse<DummyItem>> pageRequest(HttpClient httpClient) {
//         return new DummyListRequest<>(httpClient, ListRequest.<DummyItem>pagingExecutor());
//     }
// 
//     static DummyListRequest<Iterable<DummyItem>> iterableRequest(HttpClient httpClient) {
//         return new DummyListRequest<>(httpClient, ListRequest.<DummyItem>iteratingExecutor());
//     }
// }


// Path: src/test/java/com/gocardless/http/PaginatingIterableTest.java
import static org.assertj.core.api.Assertions.assertThat;
import com.gocardless.http.HttpTestUtil.DummyItem;
import com.gocardless.http.ListRequestTest.DummyListRequest;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;

                ImmutableMap.of("Authorization", "Bearer token"));
        http.assertRequestMade("GET", "/dummy?after=ID123&limit=2&id=123",
                ImmutableMap.of("Authorization", "Bearer token"));
    }

    @Test
    public void shouldCopeWithEmptyLastPage() throws Exception {
        http.enqueueResponse(200, "fixtures/first-page.json");
        http.enqueueResponse(200, "fixtures/empty-page.json");
        DummyListRequest<Iterable<DummyItem>> request =
                DummyListRequest.iterableRequest(http.client());
        request.setLimit(2);
        Iterable<DummyItem> iterable = new PaginatingIterable<>(request, http.client());
        List<DummyItem> items = Lists.newArrayList(iterable);
        assertThat(items).hasSize(2);
        assertThat(items.get(0).stringField).isEqualTo("foo");
        assertThat(items.get(0).intField).isEqualTo(111);
        assertThat(items.get(1).stringField).isEqualTo("bar");
        assertThat(items.get(1).intField).isEqualTo(222);
        http.assertRequestMade("GET", "/dummy?limit=2&id=123",
                ImmutableMap.of("Authorization", "Bearer token"));
        http.assertRequestMade("GET", "/dummy?after=ID123&limit=2&id=123",
                ImmutableMap.of("Authorization", "Bearer token"));
    }

    @Test
    public void shouldRetryOnNetworkFailure() throws Exception {
        http.enqueueNetworkFailure();
        http.enqueueResponse(200, "fixtures/first-page.json");
        http.enqueueResponse(200, "fixtures/last-page.json");
        DummyListRequest<Iterable<DummyItem>> request =