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.mock;
31
32 import com.jcabi.github.Github;
33 import com.jcabi.github.Release;
34 import com.jcabi.github.Releases;
35 import java.io.IOException;
36 import javax.json.Json;
37 import javax.json.JsonString;
38 import javax.json.JsonValue;
39 import org.hamcrest.MatcherAssert;
40 import org.hamcrest.Matchers;
41 import org.junit.Test;
42
43
44
45
46
47
48
49 @SuppressWarnings("PMD.TooManyMethods")
50 public final class MkReleaseTest {
51
52
53
54
55 @Test
56 public void canDeleteRelease() throws Exception {
57 final Releases releases = MkReleaseTest.releases();
58 final Release release = releases.create("v1.0");
59 release.delete();
60 MatcherAssert.assertThat(
61 releases.iterate().iterator().hasNext(),
62 Matchers.is(false)
63 );
64 }
65
66
67
68
69
70 @Test
71 public void canGetUrl() throws Exception {
72 final Release release = MkReleaseTest.release();
73 final Release.Smart smart = new Release.Smart(release);
74 MatcherAssert.assertThat(
75 smart.url().toString(),
76 Matchers.equalTo(this.value(release, "url"))
77 );
78 }
79
80
81
82
83
84 @Test
85 public void canGetAssetsUrl() throws Exception {
86 final Release release = MkReleaseTest.release();
87 final Release.Smart smart = new Release.Smart(release);
88 MatcherAssert.assertThat(
89 smart.assetsUrl().toString(),
90 Matchers.equalTo(this.value(release, "assets_url"))
91 );
92 }
93
94
95
96
97
98 @Test
99 public void canGetHtmlUrl() throws Exception {
100 final Release release = MkReleaseTest.release();
101 final Release.Smart smart = new Release.Smart(release);
102 MatcherAssert.assertThat(
103 smart.htmlUrl().toString(),
104 Matchers.equalTo(this.value(release, "html_url"))
105 );
106 }
107
108
109
110
111
112 @Test
113 public void canGetUploadUrl() throws Exception {
114 final Release release = MkReleaseTest.release();
115 final Release.Smart smart = new Release.Smart(release);
116 MatcherAssert.assertThat(
117 smart.uploadUrl().toString(),
118 Matchers.equalTo(this.value(release, "upload_url"))
119 );
120 }
121
122
123
124
125
126 @Test
127 public void canGetTag() throws Exception {
128 final Release release = MkReleaseTest.release();
129 final Release.Smart smart = new Release.Smart(release);
130 MatcherAssert.assertThat(
131 smart.tag(),
132 Matchers.equalTo(this.value(release, "tag_name"))
133 );
134 }
135
136
137
138
139
140 @Test
141 public void canGetCommitish() throws Exception {
142 final Release release = MkReleaseTest.release();
143 final Release.Smart smart = new Release.Smart(release);
144 MatcherAssert.assertThat(
145 smart.commitish(),
146 Matchers.equalTo(this.value(release, "target_commitish"))
147 );
148 }
149
150
151
152
153
154 @Test
155 public void canGetName() throws Exception {
156 final Release release = MkReleaseTest.release();
157 final Release.Smart smart = new Release.Smart(release);
158 MatcherAssert.assertThat(
159 smart.name(),
160 Matchers.equalTo(this.value(release, "name"))
161 );
162 }
163
164
165
166
167
168 @Test
169 public void canGetBody() throws Exception {
170 final Release release = MkReleaseTest.release();
171 final Release.Smart smart = new Release.Smart(release);
172 MatcherAssert.assertThat(
173 smart.body(),
174 Matchers.equalTo(this.value(release, "body"))
175 );
176 }
177
178
179
180
181
182 @Test
183 public void canGetCreatedAt() throws Exception {
184 final Release release = MkReleaseTest.release();
185 final Release.Smart smart = new Release.Smart(release);
186 MatcherAssert.assertThat(
187 smart.createdAt(),
188 Matchers.equalTo(new Github.Time(this.value(release, "created_at"))
189 .date()
190 )
191 );
192 }
193
194
195
196
197
198 @Test
199 public void prerelease() throws Exception {
200 final Release release = MkReleaseTest.release();
201 release.patch(
202 Json.createObjectBuilder().add("prerelease", true).build()
203 );
204 MatcherAssert.assertThat(
205 new Release.Smart(release).prerelease(),
206 Matchers.is(true)
207 );
208 }
209
210
211
212
213
214 @Test
215 public void canGetPublishedAt() throws Exception {
216 final Release release = MkReleaseTest.release();
217 final Release.Smart smart = new Release.Smart(release);
218 MatcherAssert.assertThat(
219 smart.publishedAt(),
220 Matchers.equalTo(
221 new Github.Time(this.value(release, "published_at")).date()
222 )
223 );
224 }
225
226
227
228
229
230
231
232
233 private String value(final Release release, final String name)
234 throws IOException {
235 final JsonValue jsonValue = release.json().get(name);
236 String result = null;
237 if (jsonValue instanceof JsonString) {
238 result = ((JsonString) jsonValue).getString();
239 }
240 return result;
241 }
242
243
244
245
246
247
248 private static Release release() throws Exception {
249 return MkReleaseTest.releases().create("v1");
250 }
251
252
253
254
255
256
257 private static Releases releases() throws IOException {
258 return new MkGithub().randomRepo().releases();
259 }
260 }