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.
22
22
23
23
import static com .google .common .io .Resources .getResource ;
24
24
import static com .spotify .github .FixtureHelper .loadFixture ;
25
- import static com .spotify .github .v3 .clients .IssueClient .COMMENTS_URI_NUMBER_TEMPLATE ;
26
- import static com .spotify .github .v3 .clients .IssueClient .ISSUES_URI_ID_TEMPLATE ;
25
+ import static com .spotify .github .v3 .clients .IssueClient .*;
27
26
import static com .spotify .github .v3 .clients .MockHelper .createMockResponse ;
28
27
import static java .lang .String .format ;
29
28
import static java .nio .charset .Charset .defaultCharset ;
37
36
import static org .junit .jupiter .api .Assertions .assertThrows ;
38
37
import static org .mockito .ArgumentMatchers .anyString ;
39
38
import static org .mockito .ArgumentMatchers .eq ;
40
- import static org .mockito .Mockito .mock ;
41
- import static org .mockito .Mockito .when ;
39
+ import static org .mockito .Mockito .*;
42
40
41
+ import com .google .common .collect .ImmutableMap ;
43
42
import com .google .common .collect .Lists ;
44
43
import com .google .common .io .Resources ;
45
44
import com .spotify .github .async .Async ;
46
45
import com .spotify .github .async .AsyncPage ;
47
46
import com .spotify .github .jackson .Json ;
47
+ import com .spotify .github .v3 .ImmutableUser ;
48
48
import com .spotify .github .v3 .comment .Comment ;
49
+ import com .spotify .github .v3 .comment .CommentReaction ;
50
+ import com .spotify .github .v3 .comment .CommentReactionContent ;
51
+ import com .spotify .github .v3 .comment .ImmutableCommentReaction ;
49
52
import com .spotify .github .v3 .exceptions .RequestNotOkException ;
50
53
import com .spotify .github .v3 .issues .Issue ;
51
54
import java .io .IOException ;
@@ -63,7 +66,6 @@ public class IssueClientTest {
63
66
private IssueClient issueClient ;
64
67
private Json json ;
65
68
66
-
67
69
@ BeforeEach
68
70
public void setUp () {
69
71
json = Json .create ();
@@ -94,7 +96,8 @@ public void testCommentPaginationSpliterator() throws IOException {
94
96
.thenReturn (completedFuture (lastPageResponse ));
95
97
96
98
final Iterable <AsyncPage <Comment >> pageIterator = () -> issueClient .listComments (123 );
97
- final List <Comment > listComments = Async .streamFromPaginatingIterable (pageIterator ).collect (toList ());
99
+ final List <Comment > listComments =
100
+ Async .streamFromPaginatingIterable (pageIterator ).collect (toList ());
98
101
99
102
assertThat (listComments .size (), is (30 ));
100
103
assertThat (listComments .get (0 ).id (), is (1345268 ));
@@ -161,10 +164,55 @@ public void testGetIssue() throws IOException {
161
164
assertThat (issue .labels ().get (0 ).name (), is ("bug" ));
162
165
}
163
166
167
+ @ Test
168
+ public void testCreateIssueCommentReaction () {
169
+ long commentId = 22369886 ;
170
+ CommentReactionContent reaction = CommentReactionContent .HEART ;
171
+ final CompletableFuture <CommentReaction > reactionResponse =
172
+ completedFuture (
173
+ ImmutableCommentReaction .builder ()
174
+ .id (42L )
175
+ .content (CommentReactionContent .HEART )
176
+ .user (ImmutableUser .builder ().login ("octocat" ).build ())
177
+ .build ());
178
+ final String path = format (COMMENTS_REACTION_TEMPLATE , "someowner" , "somerepo" , commentId );
179
+ final String requestBody = github .json ().toJsonUnchecked (ImmutableMap .of ("content" , reaction ));
180
+ when (github .post (eq (path ), eq (requestBody ), eq (CommentReaction .class )))
181
+ .thenReturn (reactionResponse );
182
+
183
+ final var commentReaction =
184
+ issueClient .createCommentReaction (commentId , CommentReactionContent .HEART ).join ();
185
+
186
+ assertThat (commentReaction .id (), is (42L ));
187
+ assertNotNull (commentReaction .user ());
188
+ assertThat (commentReaction .user ().login (), is ("octocat" ));
189
+ assertThat (commentReaction .content ().toString (), is (reaction .toString ()));
190
+ verify (github , times (1 )).post (eq (path ), eq (requestBody ), eq (CommentReaction .class ));
191
+ }
192
+
193
+ @ Test
194
+ public void testDeleteIssueCommentReaction () {
195
+ long issueNumber = 42 ;
196
+ long reactionId = 385825 ;
197
+ final String path =
198
+ format (COMMENTS_REACTION_ID_TEMPLATE , "someowner" , "somerepo" , issueNumber , reactionId );
199
+ final String requestBody = github .json ().toJsonUnchecked ("" );
200
+ Response mockResponse = mock (Response .class );
201
+ when (mockResponse .code ()).thenReturn (204 );
202
+ when (github .delete (eq (path ), eq (requestBody ))).thenReturn (completedFuture (mockResponse ));
203
+
204
+ final var response = issueClient .deleteCommentReaction (issueNumber , reactionId ).join ();
205
+
206
+ assertThat (response .code (), is (204 ));
207
+ assertThat (response , is (mockResponse ));
208
+ verify (github , times (1 )).delete (eq (path ), eq (requestBody ));
209
+ }
210
+
164
211
@ Test
165
212
public void testGetIssueNoIssue () {
166
213
final String path = format (ISSUES_URI_ID_TEMPLATE , "someowner" , "somerepo" , 2 );
167
- when (github .request (eq (path ), eq (Issue .class ))).thenReturn (failedFuture (new RequestNotOkException ("" , "" , 404 , "" , new HashMap <>())));
214
+ when (github .request (eq (path ), eq (Issue .class )))
215
+ .thenReturn (failedFuture (new RequestNotOkException ("" , "" , 404 , "" , new HashMap <>())));
168
216
169
217
assertThrows (CompletionException .class , () -> issueClient .getIssue (2 ).join ());
170
218
}
0 commit comments