|
21 | 21 | package com.spotify.github.v3.clients;
|
22 | 22 |
|
23 | 23 | import static com.google.common.io.Resources.getResource;
|
| 24 | +import static com.spotify.github.MockHelper.createMockHttpResponse; |
24 | 25 | import static com.spotify.github.MockHelper.createMockResponse;
|
| 26 | +import static com.spotify.github.v3.UserTest.assertUser; |
| 27 | +import static com.spotify.github.v3.clients.GitHubClient.LIST_COMMIT_TYPE_REFERENCE; |
25 | 28 | import static java.lang.String.format;
|
26 | 29 | import static java.nio.charset.Charset.defaultCharset;
|
27 | 30 | import static java.util.concurrent.CompletableFuture.completedFuture;
|
| 31 | +import static java.util.concurrent.CompletableFuture.completedStage; |
28 | 32 | import static java.util.stream.Collectors.toList;
|
29 | 33 | import static org.hamcrest.MatcherAssert.assertThat;
|
30 | 34 | import static org.hamcrest.core.Is.is;
|
|
51 | 55 | import com.spotify.github.v3.prs.requests.ImmutablePullRequestUpdate;
|
52 | 56 | import com.spotify.github.v3.prs.requests.PullRequestCreate;
|
53 | 57 | import com.spotify.github.v3.prs.requests.PullRequestUpdate;
|
| 58 | +import com.spotify.github.v3.repos.CommitItem; |
54 | 59 | import java.io.IOException;
|
55 | 60 | import java.io.Reader;
|
56 | 61 | import java.net.URI;
|
57 | 62 | import java.util.List;
|
58 | 63 | import java.util.concurrent.CompletableFuture;
|
| 64 | +import java.util.concurrent.CompletionStage; |
59 | 65 | import java.util.concurrent.ExecutionException;
|
60 | 66 | import okhttp3.Call;
|
61 | 67 | import okhttp3.Callback;
|
@@ -438,4 +444,40 @@ void testChangedFiles() throws IOException {
|
438 | 444 | assertEquals(actualFiles.get(0).filename(), expectedFiles.get(0).filename());
|
439 | 445 | assertEquals(actualFiles.get(1).filename(), expectedFiles.get(1).filename());
|
440 | 446 | }
|
| 447 | + |
| 448 | + @Test |
| 449 | + public void listCommits() throws Exception { |
| 450 | + // Given |
| 451 | + final String firstPageLink = |
| 452 | + "<https://api.github.com/repositories/10270250/pulls/20463/commits?page=2>; rel=\"next\", <https://api.github.com/repositories/10270250/pulls/20463/commits?page=4>; rel=\"last\""; |
| 453 | + final String firstPageBody = |
| 454 | + Resources.toString(getResource(this.getClass(), "pull_request_commits_page1.json"), defaultCharset()); |
| 455 | + final HttpResponse firstPageResponse = createMockResponse(firstPageLink, firstPageBody); |
| 456 | + |
| 457 | + final String secondPageLink = |
| 458 | + "<https://api.github.com/repositories/10270250/pulls/20463/commits?page=1>; rel=\"prev\", <https://api.github.com/repositories/10270250/pulls/20463/commits?page=3>; rel=\"next\", <https://api.github.com/repositories/10270250/pulls/20463/commits?page=3>; rel=\"last\", <https://api.github.com/repositories/10270250/pulls/20463/commits?page=1>; rel=\"first\""; |
| 459 | + final String secondPageBody = |
| 460 | + Resources.toString(getResource(this.getClass(), "pull_request_commits_page2.json"), defaultCharset()); |
| 461 | + final HttpResponse secondPageResponse = createMockResponse(secondPageLink, secondPageBody); |
| 462 | + |
| 463 | + final String thirdPageLink = |
| 464 | + "<https://api.github.com/repositories/10270250/pulls/20463/commits?page=2>; rel=\"prev\", <https://api.github.com/repositories/10270250/pulls/20463/commits?page=1>; rel=\"first\""; |
| 465 | + final String thirdPageBody = |
| 466 | + Resources.toString(getResource(this.getClass(), "pull_request_commits_page3.json"), defaultCharset()); |
| 467 | + final HttpResponse thirdPageResponse = createMockResponse(thirdPageLink, thirdPageBody); |
| 468 | + |
| 469 | + when(mockGithub.request("/repos/owner/repo/pulls/1/commits")) |
| 470 | + .thenReturn(completedFuture(firstPageResponse)); |
| 471 | + when(mockGithub.request("/repos/owner/repo/pulls/1/commits?page=1")) |
| 472 | + .thenReturn(completedFuture(firstPageResponse)); |
| 473 | + when(mockGithub.request("/repos/owner/repo/pulls/1/commits?page=2")) |
| 474 | + .thenReturn(completedFuture(secondPageResponse)); |
| 475 | + when(mockGithub.request("/repos/owner/repo/pulls/1/commits?page=3")) |
| 476 | + .thenReturn(completedFuture(thirdPageResponse)); |
| 477 | + |
| 478 | + final PullRequestClient pullRequestClient = PullRequestClient.create(mockGithub, "owner", "repo"); |
| 479 | + |
| 480 | + final List<CommitItem> commits = pullRequestClient.listCommits(1L).get(); |
| 481 | + assertThat(commits.size(), is(1)); |
| 482 | + } |
441 | 483 | }
|
0 commit comments