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 javax.json.Json;
33 import javax.json.JsonValue;
34 import org.hamcrest.MatcherAssert;
35 import org.hamcrest.Matchers;
36 import org.junit.Test;
37 import org.mockito.Mockito;
38
39
40
41
42
43
44
45 @SuppressWarnings("PMD.TooManyMethods")
46 public final class ReleaseTest {
47
48
49
50
51
52 @Test
53 public void fetchesUrls() throws Exception {
54 final Release release = Mockito.mock(Release.class);
55 final String url = "http://url";
56 Mockito.doReturn(
57 Json.createObjectBuilder()
58 .add("url", url)
59 .build()
60 ).when(release).json();
61 final Release.Smart smart = new Release.Smart(release);
62 MatcherAssert.assertThat(
63 smart.url().toString(),
64 Matchers.equalTo(url)
65 );
66 }
67
68
69
70
71
72 @Test
73 public void fetchesHtmlUrls() throws Exception {
74 final Release release = Mockito.mock(Release.class);
75 final String htmlurl = "http://html_url";
76 Mockito.doReturn(
77 Json.createObjectBuilder()
78 .add("html_url", htmlurl)
79 .build()
80 ).when(release).json();
81 final Release.Smart smart = new Release.Smart(release);
82 MatcherAssert.assertThat(
83 smart.htmlUrl().toString(),
84 Matchers.equalTo(htmlurl)
85 );
86 }
87
88
89
90
91
92 @Test
93 public void fetchesAssetsHtmlUrls() throws Exception {
94 final Release release = Mockito.mock(Release.class);
95 final String assetsurl = "http://assets_url";
96 Mockito.doReturn(
97 Json.createObjectBuilder()
98 .add("assets_url", assetsurl)
99 .build()
100 ).when(release).json();
101 final Release.Smart smart = new Release.Smart(release);
102 MatcherAssert.assertThat(
103 smart.assetsUrl().toString(),
104 Matchers.equalTo(assetsurl)
105 );
106 }
107
108
109
110
111
112 @Test
113 public void fetchesUploadHtmlUrls() throws Exception {
114 final Release release = Mockito.mock(Release.class);
115 final String uploadurl = "http://upload_url";
116 Mockito.doReturn(
117 Json.createObjectBuilder()
118 .add("upload_url", uploadurl)
119 .build()
120 ).when(release).json();
121 final Release.Smart smart = new Release.Smart(release);
122 MatcherAssert.assertThat(
123 smart.uploadUrl().toString(),
124 Matchers.equalTo(uploadurl)
125 );
126 }
127
128
129
130
131
132 @Test
133 public void testId() throws Exception {
134 final Release release = Mockito.mock(Release.class);
135 Mockito.doReturn(1).when(release).number();
136 final Release.Smart smart = new Release.Smart(release);
137 MatcherAssert.assertThat(
138 smart.number(),
139 Matchers.equalTo(1)
140 );
141 }
142
143
144
145
146
147 @Test
148 public void fetchTag() throws Exception {
149 final Release release = Mockito.mock(Release.class);
150 final String tag = "v1.0.0";
151 Mockito.doReturn(
152 Json.createObjectBuilder()
153 .add("tag_name", tag)
154 .build()
155 ).when(release).json();
156 final Release.Smart smart = new Release.Smart(release);
157 MatcherAssert.assertThat(
158 smart.tag(),
159 Matchers.equalTo(tag)
160 );
161 }
162
163
164
165
166
167 @Test
168 public void fetchProperties() throws Exception {
169 final Release release = Mockito.mock(Release.class);
170 final String master = "master";
171 Mockito.doReturn(
172 Json.createObjectBuilder()
173 .add("target_commitish", master)
174 .build()
175 ).when(release).json();
176 final Release.Smart smart = new Release.Smart(release);
177 MatcherAssert.assertThat(
178 smart.commitish(),
179 Matchers.equalTo(master)
180 );
181 }
182
183
184
185
186
187 @Test
188 public void fetchName() throws Exception {
189 final Release release = Mockito.mock(Release.class);
190 final String name = "v1";
191
192 Mockito.doReturn(
193 Json.createObjectBuilder()
194 .add("name", name)
195 .build()
196 ).when(release).json();
197 final Release.Smart smart = new Release.Smart(release);
198 MatcherAssert.assertThat(
199 smart.hasName(),
200 Matchers.is(true)
201 );
202 MatcherAssert.assertThat(
203 smart.name(),
204 Matchers.equalTo(name)
205 );
206 }
207
208
209
210
211
212
213 @Test
214 public void incidatesNoName() throws Exception {
215 final Release release = Mockito.mock(Release.class);
216 Mockito.doReturn(
217 Json.createObjectBuilder()
218 .add("name", JsonValue.NULL)
219 .build()
220 ).when(release).json();
221 final Release.Smart smart = new Release.Smart(release);
222 MatcherAssert.assertThat(
223 smart.hasName(),
224 Matchers.is(false)
225 );
226 }
227
228
229
230
231
232 @Test
233 public void fetchBody() throws Exception {
234 final Release release = Mockito.mock(Release.class);
235 final String description = "Description of the release";
236 Mockito.doReturn(
237 Json.createObjectBuilder()
238 .add("body", description)
239 .build()
240 ).when(release).json();
241 final Release.Smart smart = new Release.Smart(release);
242 MatcherAssert.assertThat(
243 smart.body(),
244 Matchers.equalTo(description)
245 );
246 }
247
248
249
250
251
252 @Test
253 public void fetchDescription() throws Exception {
254 final Release release = Mockito.mock(Release.class);
255 final String created = "2013-02-27T19:35:32Z";
256 Mockito.doReturn(
257 Json.createObjectBuilder()
258 .add("created_at", created)
259 .build()
260 ).when(release).json();
261 final Release.Smart smart = new Release.Smart(release);
262 MatcherAssert.assertThat(
263 smart.createdAt(),
264 Matchers.equalTo(new Github.Time(created).date())
265 );
266 }
267
268
269
270
271
272 @Test
273 public void fetchPublished() throws Exception {
274 final Release release = Mockito.mock(Release.class);
275 final String published = "2013-01-27T19:35:32Z";
276 Mockito.doReturn(
277 Json.createObjectBuilder()
278 .add("published_at", published)
279 .build()
280 ).when(release).json();
281 final Release.Smart smart = new Release.Smart(release);
282 MatcherAssert.assertThat(
283 smart.publishedAt(),
284 Matchers.equalTo(new Github.Time(published).date())
285 );
286 }
287
288
289
290
291
292 @Test
293 public void isPrerelease() throws Exception {
294 final Release release = Mockito.mock(Release.class);
295 Mockito.doReturn(
296 Json.createObjectBuilder().add("prerelease", Boolean.TRUE).build()
297 ).when(release).json();
298 MatcherAssert.assertThat(
299 new Release.Smart(release).prerelease(),
300 Matchers.is(Boolean.TRUE)
301 );
302 }
303
304
305
306
307
308 @Test
309 public void isNotPrerelease() throws Exception {
310 final Release release = Mockito.mock(Release.class);
311 Mockito.doReturn(
312 Json.createObjectBuilder().add("prerelease", "false").build()
313 ).when(release).json();
314 MatcherAssert.assertThat(
315 new Release.Smart(release).prerelease(),
316 Matchers.is(Boolean.FALSE)
317 );
318 }
319
320
321
322
323
324 @Test
325 public void missingPrerelease() throws Exception {
326 final Release release = Mockito.mock(Release.class);
327 Mockito.doReturn(
328 Json.createObjectBuilder().build()
329 ).when(release).json();
330 MatcherAssert.assertThat(
331 new Release.Smart(release).prerelease(),
332 Matchers.is(Boolean.FALSE)
333 );
334 }
335
336
337
338
339
340 @Test
341 public void isDraft() throws Exception {
342 final Release release = Mockito.mock(Release.class);
343 Mockito.doReturn(
344 Json.createObjectBuilder().add("draft", Boolean.TRUE).build()
345 ).when(release).json();
346 MatcherAssert.assertThat(
347 new Release.Smart(release).draft(),
348 Matchers.is(Boolean.TRUE)
349 );
350 }
351
352
353
354
355
356 @Test
357 public void isNotDraft() throws Exception {
358 final Release release = Mockito.mock(Release.class);
359 Mockito.doReturn(
360 Json.createObjectBuilder().add("draft", Boolean.FALSE).build()
361 ).when(release).json();
362 MatcherAssert.assertThat(
363 new Release.Smart(release).draft(),
364 Matchers.is(Boolean.FALSE)
365 );
366 }
367
368
369
370
371
372 @Test
373 public void missingDraft() throws Exception {
374 final Release release = Mockito.mock(Release.class);
375 Mockito.doReturn(
376 Json.createObjectBuilder().build()
377 ).when(release).json();
378 MatcherAssert.assertThat(
379 new Release.Smart(release).draft(),
380 Matchers.is(Boolean.FALSE)
381 );
382 }
383 }