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.google.common.base.Optional;
33 import com.jcabi.github.mock.MkGithub;
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 @SuppressWarnings("PMD.TooManyMethods")
46 public final class StatusTest {
47
48
49
50 private static final String STATE_PROP = "state";
51
52
53
54 private static final String DESCRIPTION_PROP = "description";
55
56
57
58 private static final String TARGET_PROP = "target_url";
59
60
61
62
63
64 @Test
65 public void fetchesCommit() throws Exception {
66 final Commit cmmt = StatusTest.commit();
67 MatcherAssert.assertThat(
68 new Status.Smart(
69 new RtStatus(cmmt, Json.createObjectBuilder().build())
70 ).commit(),
71 Matchers.equalTo(cmmt)
72 );
73 }
74
75
76
77
78
79 @Test
80 public void fetchesId() throws Exception {
81 final int ident = 777;
82 MatcherAssert.assertThat(
83 new Status.Smart(
84 new RtStatus(
85 StatusTest.commit(),
86 Json.createObjectBuilder().add("id", ident).build()
87 )
88 ).identifier(),
89 Matchers.equalTo(ident)
90 );
91 }
92
93
94
95
96
97 @Test
98 public void fetchesUrl() throws Exception {
99 final String url = "http://api.jcabi-github.invalid/wherever";
100 MatcherAssert.assertThat(
101 new Status.Smart(
102 new RtStatus(
103 StatusTest.commit(),
104 Json.createObjectBuilder().add("url", url).build()
105 )
106 ).url(),
107 Matchers.equalTo(url)
108 );
109 }
110
111
112
113
114
115 @Test
116 public void fetchesErrorState() throws Exception {
117 MatcherAssert.assertThat(
118 new Status.Smart(
119 new RtStatus(
120 StatusTest.commit(),
121 Json.createObjectBuilder()
122 .add(StatusTest.STATE_PROP, "error").build()
123 )
124 ).state(),
125 Matchers.equalTo(Status.State.ERROR)
126 );
127 }
128
129
130
131
132
133 @Test
134 public void fetchesFailureState() throws Exception {
135 MatcherAssert.assertThat(
136 new Status.Smart(
137 new RtStatus(
138 StatusTest.commit(),
139 Json.createObjectBuilder()
140 .add(StatusTest.STATE_PROP, "failure").build()
141 )
142 ).state(),
143 Matchers.equalTo(Status.State.FAILURE)
144 );
145 }
146
147
148
149
150
151 @Test
152 public void fetchesPendingState() throws Exception {
153 MatcherAssert.assertThat(
154 new Status.Smart(
155 new RtStatus(
156 StatusTest.commit(),
157 Json.createObjectBuilder()
158 .add(StatusTest.STATE_PROP, "pending").build()
159 )
160 ).state(),
161 Matchers.equalTo(Status.State.PENDING)
162 );
163 }
164
165
166
167
168
169 @Test
170 public void fetchesSuccessState() throws Exception {
171 MatcherAssert.assertThat(
172 new Status.Smart(
173 new RtStatus(
174 StatusTest.commit(),
175 Json.createObjectBuilder()
176 .add(StatusTest.STATE_PROP, "success").build()
177 )
178 ).state(),
179 Matchers.equalTo(Status.State.SUCCESS)
180 );
181 }
182
183
184
185
186
187 @Test
188 public void fetchesPresentTargetUrl() throws Exception {
189 final String url = "http://api.jcabi-github.invalid/good-luck";
190 MatcherAssert.assertThat(
191 new Status.Smart(
192 new RtStatus(
193 StatusTest.commit(),
194 Json.createObjectBuilder()
195 .add(StatusTest.TARGET_PROP, url).build()
196 )
197 ).targetUrl(),
198 Matchers.equalTo(Optional.of(url))
199 );
200 }
201
202
203
204
205
206 @Test
207 public void fetchesAbsentTargetUrl() throws Exception {
208 MatcherAssert.assertThat(
209 new Status.Smart(
210 new RtStatus(
211 StatusTest.commit(),
212 Json.createObjectBuilder().build()
213 )
214 ).targetUrl(),
215 Matchers.equalTo(Optional.<String>absent())
216 );
217 }
218
219
220
221
222
223 @Test
224 public void fetchesNullTargetUrl() throws Exception {
225 MatcherAssert.assertThat(
226 new Status.Smart(
227 new RtStatus(
228 StatusTest.commit(),
229 Json.createObjectBuilder()
230 .addNull(StatusTest.TARGET_PROP).build()
231 )
232 ).targetUrl(),
233 Matchers.equalTo(Optional.<String>absent())
234 );
235 }
236
237
238
239
240
241 @Test
242 public void fetchesPresentDescription() throws Exception {
243 final String description = "Mostly harmless";
244 MatcherAssert.assertThat(
245 new Status.Smart(
246 new RtStatus(
247 StatusTest.commit(),
248 Json.createObjectBuilder()
249 .add(StatusTest.DESCRIPTION_PROP, description).build()
250 )
251 ).description(),
252 Matchers.equalTo(description)
253 );
254 }
255
256
257
258
259
260 @Test
261 public void fetchesAbsentDescription() throws Exception {
262 MatcherAssert.assertThat(
263 new Status.Smart(
264 new RtStatus(
265 StatusTest.commit(),
266 Json.createObjectBuilder().build()
267 )
268 ).description(),
269 Matchers.equalTo("")
270 );
271 }
272
273
274
275
276
277 @Test
278 public void fetchesNullDescription() throws Exception {
279 MatcherAssert.assertThat(
280 new Status.Smart(
281 new RtStatus(
282 StatusTest.commit(),
283 Json.createObjectBuilder()
284 .addNull(StatusTest.DESCRIPTION_PROP).build()
285 )
286 ).description(),
287 Matchers.equalTo("")
288 );
289 }
290
291
292
293
294
295 @Test
296 public void fetchesContext() throws Exception {
297 final String context = "jcabi/github/tester";
298 MatcherAssert.assertThat(
299 new Status.Smart(
300 new RtStatus(
301 StatusTest.commit(),
302 Json.createObjectBuilder().add("context", context).build()
303 )
304 ).context(),
305 Matchers.equalTo(context)
306 );
307 }
308
309
310
311
312
313 @Test
314 public void fetchesCreatedAt() throws Exception {
315 final String when = "2015-02-27T19:35:32Z";
316 MatcherAssert.assertThat(
317 new Status.Smart(
318 new RtStatus(
319 StatusTest.commit(),
320 Json.createObjectBuilder().add("created_at", when).build()
321 )
322 ).createdAt(),
323 Matchers.equalTo(new Github.Time(when).date())
324 );
325 }
326
327
328
329
330
331 @Test
332 public void fetchesUpdatedAt() throws Exception {
333 final String when = "2013-02-27T19:35:32Z";
334 MatcherAssert.assertThat(
335 new Status.Smart(
336 new RtStatus(
337 StatusTest.commit(),
338 Json.createObjectBuilder().add("updated_at", when).build()
339 )
340 ).updatedAt(),
341 Matchers.equalTo(new Github.Time(when).date())
342 );
343 }
344
345
346
347
348
349 @Test
350 public void fetchesCreator() throws Exception {
351 final String login = "bob";
352 MatcherAssert.assertThat(
353 new Status.Smart(
354 new RtStatus(
355 StatusTest.commit(),
356 Json.createObjectBuilder()
357 .add(
358 "creator",
359 Json.createObjectBuilder()
360 .add("login", login).build()
361 ).build()
362 )
363 ).creator().login(),
364 Matchers.equalTo(login)
365 );
366 }
367
368
369
370
371
372
373 private static Commit commit() throws Exception {
374 return new MkGithub().randomRepo().git().commits()
375 .get("d288364af5028c72e2a2c91c29343bae11fffcbe");
376 }
377 }