1
2
3
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
15
16
17
18 @OAuthScope(OAuthScope.Scope.GIST)
19 final class RtGistCommentsITCase {
20
21
22
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
40
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
58
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
76
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 }