View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github;
6   
7   import java.io.IOException;
8   import java.util.Collections;
9   import org.hamcrest.MatcherAssert;
10  import org.hamcrest.Matchers;
11  import org.junit.jupiter.api.Test;
12  
13  /**
14   * Integration test for {@link RtGistComments}.
15   * @see <a href="https://developer.github.com/v3/gists/comments/">Gist Comments API</a>
16   * @since 0.8
17   */
18  @OAuthScope(OAuthScope.Scope.GIST)
19  final class RtGistCommentsITCase {
20      /**
21       * RtGistComments can create a comment.
22       * @throws Exception if some problem inside
23       */
24      @Test
25      void createComment() throws Exception {
26          final Gist gist = RtGistCommentsITCase.gist();
27          final GistComments comments = gist.comments();
28          final GistComment comment = comments.post("gist comment");
29          MatcherAssert.assertThat(
30              "String does not start with expected value",
31              new GistComment.Smart(comment).body(),
32              Matchers.startsWith("gist")
33          );
34          comment.remove();
35          gist.github().gists().remove(gist.identifier());
36      }
37  
38      /**
39       * RtGistComments can get a comment.
40       * @throws Exception if some problem inside
41       */
42      @Test
43      void getComment() throws Exception {
44          final Gist gist = RtGistCommentsITCase.gist();
45          final GistComments comments = gist.comments();
46          final GistComment comment = comments.post("test comment");
47          MatcherAssert.assertThat(
48              "Values are not equal",
49              comments.get(comment.number()),
50              Matchers.equalTo(comment)
51          );
52          comment.remove();
53          gist.github().gists().remove(gist.identifier());
54      }
55  
56      /**
57       * RtGistComments can iterate all gist comments.
58       * @throws Exception if some problem inside
59       */
60      @Test
61      void iterateComments() throws Exception {
62          final Gist gist = RtGistCommentsITCase.gist();
63          final GistComments comments = gist.comments();
64          final GistComment comment = comments.post("comment");
65          MatcherAssert.assertThat(
66              "Collection does not contain expected item",
67              comments.iterate(),
68              Matchers.hasItem(comment)
69          );
70          comment.remove();
71          gist.github().gists().remove(gist.identifier());
72      }
73  
74      /**
75       * Return gist to test.
76       * @return Gist
77       */
78      private static Gist gist() throws IOException {
79          return GitHubIT
80              .connect()
81              .gists()
82              .create(
83                  Collections.singletonMap("file.txt",  "file content"), false
84              );
85      }
86  }