77 * Licensed under the Apache License, Version 2.0 (the "License");
88 * you may not use this file except in compliance with the License.
99 * You may obtain a copy of the License at
10- *
10+ *
1111 * http://www.apache.org/licenses/LICENSE-2.0
12- *
12+ *
1313 * Unless required by applicable law or agreed to in writing, software
1414 * distributed under the License is distributed on an "AS IS" BASIS,
1515 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2222
2323import static com .google .common .io .Resources .getResource ;
2424import 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 .*;
2726import static com .spotify .github .v3 .clients .MockHelper .createMockResponse ;
2827import static java .lang .String .format ;
2928import static java .nio .charset .Charset .defaultCharset ;
3736import static org .junit .jupiter .api .Assertions .assertThrows ;
3837import static org .mockito .ArgumentMatchers .anyString ;
3938import 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 .*;
4240
41+ import com .google .common .collect .ImmutableMap ;
4342import com .google .common .collect .Lists ;
4443import com .google .common .io .Resources ;
4544import com .spotify .github .async .Async ;
4645import com .spotify .github .async .AsyncPage ;
4746import com .spotify .github .jackson .Json ;
47+ import com .spotify .github .v3 .ImmutableUser ;
4848import 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 ;
4952import com .spotify .github .v3 .exceptions .RequestNotOkException ;
5053import com .spotify .github .v3 .issues .Issue ;
5154import java .io .IOException ;
@@ -63,7 +66,6 @@ public class IssueClientTest {
6366 private IssueClient issueClient ;
6467 private Json json ;
6568
66-
6769 @ BeforeEach
6870 public void setUp () {
6971 json = Json .create ();
@@ -94,7 +96,8 @@ public void testCommentPaginationSpliterator() throws IOException {
9496 .thenReturn (completedFuture (lastPageResponse ));
9597
9698 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 ());
98101
99102 assertThat (listComments .size (), is (30 ));
100103 assertThat (listComments .get (0 ).id (), is (1345268 ));
@@ -161,10 +164,55 @@ public void testGetIssue() throws IOException {
161164 assertThat (issue .labels ().get (0 ).name (), is ("bug" ));
162165 }
163166
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+
164211 @ Test
165212 public void testGetIssueNoIssue () {
166213 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 <>())));
168216
169217 assertThrows (CompletionException .class , () -> issueClient .getIssue (2 ).join ());
170218 }
0 commit comments