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 com.jcabi.log.Logger;
34 import java.util.Date;
35 import org.hamcrest.MatcherAssert;
36 import org.hamcrest.Matchers;
37 import org.hamcrest.core.IsEqual;
38 import org.junit.AfterClass;
39 import org.junit.Assume;
40 import org.junit.BeforeClass;
41 import org.junit.Ignore;
42 import org.junit.Test;
43
44
45
46
47
48
49
50 @OAuthScope(Scope.REPO)
51 public final class RtIssueITCase {
52
53
54
55 private static Repos repos;
56
57
58
59
60 private static Repo repo;
61
62
63
64
65
66 @BeforeClass
67 public static void setUp() throws Exception {
68 final Github github = new GithubIT().connect();
69 repos = github.repos();
70 repo = new RepoRule().repo(repos);
71 }
72
73
74
75
76
77 @AfterClass
78 public static void tearDown() throws Exception {
79 if (repos != null && repo != null) {
80 repos.remove(repo.coordinates());
81 }
82 }
83
84
85
86
87
88
89 @Ignore
90 @Test
91 public void talksInGithubProject() throws Exception {
92 final Issue issue = RtIssueITCase.issue();
93 final Comment comment = issue.comments().post("hey, works?");
94 MatcherAssert.assertThat(
95 new Comment.Smart(comment).body(),
96 Matchers.startsWith("hey, ")
97 );
98 MatcherAssert.assertThat(
99 issue.comments().iterate(new Date(0L)),
100 Matchers.<Comment>iterableWithSize(1)
101 );
102 final User.Smart author = new User.Smart(
103 new Comment.Smart(comment)
104 .author()
105 );
106 final User.Smart self = new User.Smart(
107 issue.repo().github().users().self()
108 );
109 if (author.hasName() && self.hasName()) {
110 MatcherAssert.assertThat(
111 author.name(),
112 Matchers.equalTo(
113 self.name()
114 )
115 );
116 }
117 comment.remove();
118 }
119
120
121
122
123
124 @Test
125 public void changesTitleAndBody() throws Exception {
126 final Issue issue = RtIssueITCase.issue();
127 new Issue.Smart(issue).title("test one more time");
128 MatcherAssert.assertThat(
129 new Issue.Smart(issue).title(),
130 Matchers.startsWith("test o")
131 );
132 new Issue.Smart(issue).body("some new body of the issue");
133 MatcherAssert.assertThat(
134 new Issue.Smart(issue).body(),
135 Matchers.startsWith("some new ")
136 );
137 }
138
139
140
141
142
143 @Test
144 public void changesIssueState() throws Exception {
145 final Issue issue = RtIssueITCase.issue();
146 new Issue.Smart(issue).close();
147 MatcherAssert.assertThat(
148 new Issue.Smart(issue).isOpen(),
149 Matchers.is(false)
150 );
151 new Issue.Smart(issue).open();
152 MatcherAssert.assertThat(
153 new Issue.Smart(issue).isOpen(),
154 Matchers.is(true)
155 );
156 }
157
158
159
160
161
162
163
164
165
166
167
168
169
170 @Test
171 public void identifyAssignee() throws Exception {
172 final Issue issue = RtIssueITCase.issue();
173 final String login = issue.repo().github().users().self().login();
174 try {
175 new Issue.Smart(issue).assign(login);
176 } catch (final AssertionError error) {
177 Logger.warn(this, "Test failed with error: %s", error.getMessage());
178 Assume.assumeFalse(
179 "Something wrong with your test account. Read test's java-doc.",
180 true
181 );
182 }
183 final User assignee = new Issue.Smart(issue).assignee();
184 MatcherAssert.assertThat(
185 assignee.login(),
186 Matchers.equalTo(login)
187 );
188 }
189
190
191
192
193 @Test
194 public void checksForPullRequest() throws Exception {
195 final Issue issue = RtIssueITCase.issue();
196 MatcherAssert.assertThat(
197 new Issue.Smart(issue).isPull(),
198 Matchers.is(false)
199 );
200 }
201
202
203
204
205
206 @Test
207 public void listsIssueEvents() throws Exception {
208 final Issue issue = RtIssueITCase.issue();
209 new Issue.Smart(issue).close();
210 MatcherAssert.assertThat(
211 new Event.Smart(issue.events().iterator().next()).type(),
212 Matchers.equalTo(Event.CLOSED)
213 );
214 }
215
216
217
218
219
220 @Test
221 public void findsLatestEvent() throws Exception {
222 final Issue.Smart issue = new Issue.Smart(RtIssueITCase.issue());
223 issue.close();
224 MatcherAssert.assertThat(
225 new Event.Smart(
226 new Issue.Smart(issue).latestEvent(Event.CLOSED)
227 ).author().login(),
228 Matchers.equalTo(issue.author().login())
229 );
230 }
231
232
233
234
235
236
237 @Test
238 public void issueAlwaysExistsInGithub() throws Exception {
239 MatcherAssert.assertThat(
240 new Issue.Smart(RtIssueITCase.issue()).exists(), Matchers.is(true)
241 );
242 }
243
244
245
246
247
248 @Test
249 public void locks() throws Exception {
250 final Issue issue = new Issue.Smart(RtIssueITCase.issue());
251 issue.lock("off-topic");
252 MatcherAssert.assertThat(
253 issue.isLocked(),
254 new IsEqual<>(true)
255 );
256 }
257
258
259
260
261
262 @Test
263 public void unlocks() throws Exception {
264 final Issue issue = new Issue.Smart(RtIssueITCase.issue());
265 issue.lock("too heated");
266 issue.unlock();
267 MatcherAssert.assertThat(
268 issue.isLocked(),
269 new IsEqual<>(false)
270 );
271 }
272
273
274
275
276
277
278 private static Issue issue() throws Exception {
279 return repo.issues().create("test issue title", "test issue body");
280 }
281
282 }