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 @Test
132 public void testId() {
133 final Release release = Mockito.mock(Release.class);
134 Mockito.doReturn(1).when(release).number();
135 final Release.Smart smart = new Release.Smart(release);
136 MatcherAssert.assertThat(
137 smart.number(),
138 Matchers.equalTo(1)
139 );
140 }
141
142
143
144
145
146 @Test
147 public void fetchTag() throws Exception {
148 final Release release = Mockito.mock(Release.class);
149 final String tag = "v1.0.0";
150 Mockito.doReturn(
151 Json.createObjectBuilder()
152 .add("tag_name", tag)
153 .build()
154 ).when(release).json();
155 final Release.Smart smart = new Release.Smart(release);
156 MatcherAssert.assertThat(
157 smart.tag(),
158 Matchers.equalTo(tag)
159 );
160 }
161
162
163
164
165
166 @Test
167 public void fetchProperties() throws Exception {
168 final Release release = Mockito.mock(Release.class);
169 final String master = "master";
170 Mockito.doReturn(
171 Json.createObjectBuilder()
172 .add("target_commitish", master)
173 .build()
174 ).when(release).json();
175 final Release.Smart smart = new Release.Smart(release);
176 MatcherAssert.assertThat(
177 smart.commitish(),
178 Matchers.equalTo(master)
179 );
180 }
181
182
183
184
185
186 @Test
187 public void fetchName() throws Exception {
188 final Release release = Mockito.mock(Release.class);
189 final String name = "v1";
190
191 Mockito.doReturn(
192 Json.createObjectBuilder()
193 .add("name", name)
194 .build()
195 ).when(release).json();
196 final Release.Smart smart = new Release.Smart(release);
197 MatcherAssert.assertThat(
198 smart.hasName(),
199 Matchers.is(true)
200 );
201 MatcherAssert.assertThat(
202 smart.name(),
203 Matchers.equalTo(name)
204 );
205 }
206
207
208
209
210
211
212 @Test
213 public void incidatesNoName() throws Exception {
214 final Release release = Mockito.mock(Release.class);
215 Mockito.doReturn(
216 Json.createObjectBuilder()
217 .add("name", JsonValue.NULL)
218 .build()
219 ).when(release).json();
220 final Release.Smart smart = new Release.Smart(release);
221 MatcherAssert.assertThat(
222 smart.hasName(),
223 Matchers.is(false)
224 );
225 }
226
227
228
229
230
231 @Test
232 public void fetchBody() throws Exception {
233 final Release release = Mockito.mock(Release.class);
234 final String description = "Description of the release";
235 Mockito.doReturn(
236 Json.createObjectBuilder()
237 .add("body", description)
238 .build()
239 ).when(release).json();
240 final Release.Smart smart = new Release.Smart(release);
241 MatcherAssert.assertThat(
242 smart.body(),
243 Matchers.equalTo(description)
244 );
245 }
246
247
248
249
250
251 @Test
252 public void fetchDescription() throws Exception {
253 final Release release = Mockito.mock(Release.class);
254 final String created = "2013-02-27T19:35:32Z";
255 Mockito.doReturn(
256 Json.createObjectBuilder()
257 .add("created_at", created)
258 .build()
259 ).when(release).json();
260 final Release.Smart smart = new Release.Smart(release);
261 MatcherAssert.assertThat(
262 smart.createdAt(),
263 Matchers.equalTo(new Github.Time(created).date())
264 );
265 }
266
267
268
269
270
271 @Test
272 public void fetchPublished() throws Exception {
273 final Release release = Mockito.mock(Release.class);
274 final String published = "2013-01-27T19:35:32Z";
275 Mockito.doReturn(
276 Json.createObjectBuilder()
277 .add("published_at", published)
278 .build()
279 ).when(release).json();
280 final Release.Smart smart = new Release.Smart(release);
281 MatcherAssert.assertThat(
282 smart.publishedAt(),
283 Matchers.equalTo(new Github.Time(published).date())
284 );
285 }
286
287
288
289
290
291 @Test
292 public void isPrerelease() throws Exception {
293 final Release release = Mockito.mock(Release.class);
294 Mockito.doReturn(
295 Json.createObjectBuilder().add("prerelease", Boolean.TRUE).build()
296 ).when(release).json();
297 MatcherAssert.assertThat(
298 new Release.Smart(release).prerelease(),
299 Matchers.is(Boolean.TRUE)
300 );
301 }
302
303
304
305
306
307 @Test
308 public void isNotPrerelease() throws Exception {
309 final Release release = Mockito.mock(Release.class);
310 Mockito.doReturn(
311 Json.createObjectBuilder().add("prerelease", "false").build()
312 ).when(release).json();
313 MatcherAssert.assertThat(
314 new Release.Smart(release).prerelease(),
315 Matchers.is(Boolean.FALSE)
316 );
317 }
318
319
320
321
322
323 @Test
324 public void missingPrerelease() throws Exception {
325 final Release release = Mockito.mock(Release.class);
326 Mockito.doReturn(
327 Json.createObjectBuilder().build()
328 ).when(release).json();
329 MatcherAssert.assertThat(
330 new Release.Smart(release).prerelease(),
331 Matchers.is(Boolean.FALSE)
332 );
333 }
334
335
336
337
338
339 @Test
340 public void isDraft() throws Exception {
341 final Release release = Mockito.mock(Release.class);
342 Mockito.doReturn(
343 Json.createObjectBuilder().add("draft", Boolean.TRUE).build()
344 ).when(release).json();
345 MatcherAssert.assertThat(
346 new Release.Smart(release).draft(),
347 Matchers.is(Boolean.TRUE)
348 );
349 }
350
351
352
353
354
355 @Test
356 public void isNotDraft() throws Exception {
357 final Release release = Mockito.mock(Release.class);
358 Mockito.doReturn(
359 Json.createObjectBuilder().add("draft", Boolean.FALSE).build()
360 ).when(release).json();
361 MatcherAssert.assertThat(
362 new Release.Smart(release).draft(),
363 Matchers.is(Boolean.FALSE)
364 );
365 }
366
367
368
369
370
371 @Test
372 public void missingDraft() throws Exception {
373 final Release release = Mockito.mock(Release.class);
374 Mockito.doReturn(
375 Json.createObjectBuilder().build()
376 ).when(release).json();
377 MatcherAssert.assertThat(
378 new Release.Smart(release).draft(),
379 Matchers.is(Boolean.FALSE)
380 );
381 }
382 }