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