1
2
3
4
5 package com.jcabi.github;
6
7 import jakarta.json.Json;
8 import java.io.IOException;
9 import java.util.Collections;
10 import org.hamcrest.MatcherAssert;
11 import org.hamcrest.Matchers;
12 import org.junit.jupiter.api.Test;
13
14
15
16
17
18
19 @OAuthScope(OAuthScope.Scope.GIST)
20 final class RtGistCommentITCase {
21
22
23
24
25
26 @Test
27 void removeItself() throws Exception {
28 final Gist gist = RtGistCommentITCase.gist();
29 final String body = "comment body";
30 final GistComments comments = gist.comments();
31 final GistComment comment = comments.post(body);
32 MatcherAssert.assertThat(
33 "Collection does not contain expected item",
34 comments.iterate(),
35 Matchers.hasItem(comment)
36 );
37 comment.remove();
38 MatcherAssert.assertThat(
39 "Collection does not contain expected item",
40 comments.iterate(),
41 Matchers.not(Matchers.hasItem(comment))
42 );
43 gist.github().gists().remove(gist.identifier());
44 }
45
46
47
48
49
50 @Test
51 void fetchAsJson() throws Exception {
52 final Gist gist = RtGistCommentITCase.gist();
53 final GistComments comments = gist.comments();
54 final GistComment comment = comments.post("comment");
55 MatcherAssert.assertThat(
56 "Values are not equal",
57 comment.json().getInt("id"),
58 Matchers.equalTo(comment.number())
59 );
60 comment.remove();
61 gist.github().gists().remove(gist.identifier());
62 }
63
64
65
66
67
68 @Test
69 void executePatchRequest() throws Exception {
70 final Gist gist = RtGistCommentITCase.gist();
71 final GistComments comments = gist.comments();
72 final GistComment comment = comments.post("test comment");
73 MatcherAssert.assertThat(
74 "String does not start with expected value",
75 new GistComment.Smart(comment).body(),
76 Matchers.startsWith("test")
77 );
78 comment.patch(Json.createObjectBuilder().add("body", "hi!").build());
79 MatcherAssert.assertThat(
80 "String does not start with expected value",
81 new GistComment.Smart(comment).body(),
82 Matchers.startsWith("hi")
83 );
84 comment.remove();
85 gist.github().gists().remove(gist.identifier());
86 }
87
88
89
90
91
92 @Test
93 void changeCommentBody() throws Exception {
94 final Gist gist = RtGistCommentITCase.gist();
95 final GistComments comments = gist.comments();
96 final GistComment comment = comments.post("hi there");
97 MatcherAssert.assertThat(
98 "String does not end with expected value",
99 new GistComment.Smart(comment).body(),
100 Matchers.endsWith("there")
101 );
102 new GistComment.Smart(comment).body("hello there");
103 MatcherAssert.assertThat(
104 "String does not start with expected value",
105 new GistComment.Smart(comment).body(),
106 Matchers.startsWith("hello")
107 );
108 comment.remove();
109 gist.github().gists().remove(gist.identifier());
110 }
111
112
113
114
115
116 private static Gist gist() throws IOException {
117 return GitHubIT
118 .connect()
119 .gists()
120 .create(
121 Collections.singletonMap("file.txt", "file content"), false
122 );
123 }
124 }