|
7 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | * you may not use this file except in compliance with the License. |
9 | 9 | * You may obtain a copy of the License at |
10 | | - * |
| 10 | + * |
11 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | - * |
| 12 | + * |
13 | 13 | * Unless required by applicable law or agreed to in writing, software |
14 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
20 | 20 |
|
21 | 21 | package com.spotify.github.v3.clients; |
22 | 22 |
|
23 | | -import static com.google.common.io.Resources.getResource; |
| 23 | +import java.io.IOException; |
| 24 | +import java.io.Reader; |
| 25 | +import java.net.URI; |
24 | 26 | import static java.nio.charset.Charset.defaultCharset; |
| 27 | +import java.util.concurrent.CompletableFuture; |
| 28 | +import java.util.concurrent.ExecutionException; |
| 29 | + |
| 30 | +import org.apache.commons.io.IOUtils; |
25 | 31 | import static org.hamcrest.MatcherAssert.assertThat; |
26 | 32 | import static org.hamcrest.core.Is.is; |
27 | | -import static org.junit.jupiter.api.Assertions.*; |
| 33 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 34 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 35 | +import org.junit.jupiter.api.BeforeEach; |
| 36 | +import org.junit.jupiter.api.Test; |
| 37 | +import org.mockito.ArgumentCaptor; |
28 | 38 | import static org.mockito.ArgumentMatchers.any; |
29 | | -import static org.mockito.Mockito.*; |
| 39 | +import static org.mockito.Mockito.doNothing; |
| 40 | +import static org.mockito.Mockito.mock; |
| 41 | +import static org.mockito.Mockito.when; |
30 | 42 |
|
31 | 43 | import com.google.common.collect.ImmutableList; |
32 | 44 | import com.google.common.io.Resources; |
| 45 | +import static com.google.common.io.Resources.getResource; |
33 | 46 | import com.spotify.github.v3.exceptions.RequestNotOkException; |
| 47 | +import com.spotify.github.v3.prs.Comment; |
34 | 48 | import com.spotify.github.v3.prs.ImmutableRequestReviewParameters; |
35 | 49 | import com.spotify.github.v3.prs.PullRequest; |
36 | 50 | import com.spotify.github.v3.prs.ReviewRequests; |
37 | 51 | import com.spotify.github.v3.prs.requests.ImmutablePullRequestCreate; |
38 | 52 | import com.spotify.github.v3.prs.requests.ImmutablePullRequestUpdate; |
39 | 53 | import com.spotify.github.v3.prs.requests.PullRequestCreate; |
40 | 54 | import com.spotify.github.v3.prs.requests.PullRequestUpdate; |
41 | | -import java.io.IOException; |
42 | | -import java.io.Reader; |
43 | | -import java.net.URI; |
44 | | -import java.util.concurrent.CompletableFuture; |
45 | | -import java.util.concurrent.ExecutionException; |
46 | | -import okhttp3.*; |
47 | | -import org.apache.commons.io.IOUtils; |
48 | | -import org.junit.jupiter.api.BeforeEach; |
49 | | -import org.junit.jupiter.api.Test; |
50 | | -import org.mockito.ArgumentCaptor; |
| 55 | + |
| 56 | +import okhttp3.Call; |
| 57 | +import okhttp3.Callback; |
| 58 | +import okhttp3.MediaType; |
| 59 | +import okhttp3.OkHttpClient; |
| 60 | +import okhttp3.Protocol; |
| 61 | +import okhttp3.Request; |
| 62 | +import okhttp3.Response; |
| 63 | +import okhttp3.ResponseBody; |
51 | 64 |
|
52 | 65 | public class PullRequestClientTest { |
53 | 66 |
|
@@ -309,4 +322,54 @@ public void testGetDiff() throws Throwable { |
309 | 322 |
|
310 | 323 | assertEquals(getFixture("diff.txt"), IOUtils.toString(diffReader)); |
311 | 324 | } |
| 325 | + |
| 326 | + @Test |
| 327 | + public void testCreateCommentReply() throws Throwable { |
| 328 | + final Call call = mock(Call.class); |
| 329 | + final ArgumentCaptor<Callback> capture = ArgumentCaptor.forClass(Callback.class); |
| 330 | + doNothing().when(call).enqueue(capture.capture()); |
| 331 | + |
| 332 | + final Response response = |
| 333 | + new Response.Builder() |
| 334 | + .code(201) |
| 335 | + .protocol(Protocol.HTTP_1_1) |
| 336 | + .message("Created") |
| 337 | + .body( |
| 338 | + ResponseBody.create( |
| 339 | + MediaType.get("application/json"), |
| 340 | + getFixture("pull_request_review_comment_reply.json"))) |
| 341 | + .request(new Request.Builder().url("http://localhost/").build()) |
| 342 | + .build(); |
| 343 | + |
| 344 | + when(client.newCall(any())).thenReturn(call); |
| 345 | + |
| 346 | + final PullRequestClient pullRequestClient = |
| 347 | + PullRequestClient.create(github, "owner", "repo"); |
| 348 | + |
| 349 | + final String replyBody = "Thanks for the feedback!"; |
| 350 | + final CompletableFuture<Comment> result = |
| 351 | + pullRequestClient.createCommentReply(1L, 123L, replyBody); |
| 352 | + |
| 353 | + capture.getValue().onResponse(call, response); |
| 354 | + |
| 355 | + Comment comment = result.get(); |
| 356 | + |
| 357 | + assertThat(comment.body(), is("Great stuff!")); |
| 358 | + assertThat(comment.id(), is(10L)); |
| 359 | + assertThat(comment.diffHunk(), is("@@ -16,33 +16,40 @@ public class Connection : IConnection...")); |
| 360 | + assertThat(comment.path(), is("file1.txt")); |
| 361 | + assertThat(comment.position(), is(1)); |
| 362 | + assertThat(comment.originalPosition(), is(4)); |
| 363 | + assertThat(comment.commitId(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e")); |
| 364 | + assertThat(comment.originalCommitId(), is("9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840")); |
| 365 | + assertThat(comment.inReplyToId(), is(426899381L)); |
| 366 | + assertThat(comment.authorAssociation(), is("NONE")); |
| 367 | + assertThat(comment.user().login(), is("octocat")); |
| 368 | + assertThat(comment.startLine(), is(1)); |
| 369 | + assertThat(comment.originalStartLine(), is(1)); |
| 370 | + assertThat(comment.startSide(), is("RIGHT")); |
| 371 | + assertThat(comment.line(), is(2)); |
| 372 | + assertThat(comment.originalLine(), is(2)); |
| 373 | + assertThat(comment.side(), is("RIGHT")); |
| 374 | + } |
312 | 375 | } |
0 commit comments