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 java.net.URL;
33 import javax.json.Json;
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 class ReleaseAssetTest {
47
48
49
50
51
52 @Test
53 public final void fetchesUrl() throws Exception {
54 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
55
56 final String prop = "https://api.github.com/repos/octo/Hello/releases/assets/1";
57 Mockito.doReturn(
58 Json.createObjectBuilder()
59 .add("url", prop)
60 .build()
61 ).when(releaseAsset).json();
62 MatcherAssert.assertThat(
63 new ReleaseAsset.Smart(releaseAsset).url(),
64 Matchers.is(new URL(prop))
65 );
66 }
67
68
69
70
71
72 @Test
73 public final void fetchesName() throws Exception {
74 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
75 final String prop = "assetname.ext";
76 Mockito.doReturn(
77 Json.createObjectBuilder()
78 .add("name", prop)
79 .build()
80 ).when(releaseAsset).json();
81 MatcherAssert.assertThat(
82 new ReleaseAsset.Smart(releaseAsset).name(),
83 Matchers.is(prop)
84 );
85 }
86
87
88
89
90
91 @Test
92 public final void fetchesLabel() throws Exception {
93 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
94 final String prop = "short description";
95 Mockito.doReturn(
96 Json.createObjectBuilder()
97 .add("label", prop)
98 .build()
99 ).when(releaseAsset).json();
100 MatcherAssert.assertThat(
101 new ReleaseAsset.Smart(releaseAsset).label(),
102 Matchers.is(prop)
103 );
104 }
105
106
107
108
109
110 @Test
111 public final void fetchesState() throws Exception {
112 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
113 final String prop = "uploaded";
114 Mockito.doReturn(
115 Json.createObjectBuilder()
116 .add("state", prop)
117 .build()
118 ).when(releaseAsset).json();
119 MatcherAssert.assertThat(
120 new ReleaseAsset.Smart(releaseAsset).state(),
121 Matchers.is(prop)
122 );
123 }
124
125
126
127
128
129 @Test
130 public final void fetchesContentType() throws Exception {
131 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
132 final String prop = "application/zip";
133 Mockito.doReturn(
134 Json.createObjectBuilder()
135 .add("content_type", prop)
136 .build()
137 ).when(releaseAsset).json();
138 MatcherAssert.assertThat(
139 new ReleaseAsset.Smart(releaseAsset).contentType(),
140 Matchers.is(prop)
141 );
142 }
143
144
145
146
147
148 @Test
149 public final void fetchesSize() throws Exception {
150 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
151 final int prop = 1024;
152 Mockito.doReturn(
153 Json.createObjectBuilder()
154 .add("size", prop)
155 .build()
156 ).when(releaseAsset).json();
157 MatcherAssert.assertThat(
158 new ReleaseAsset.Smart(releaseAsset).size(),
159 Matchers.is(prop)
160 );
161 }
162
163
164
165
166
167 @Test
168 public final void fetchesDownloadCount() throws Exception {
169 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
170 final int prop = 42;
171 Mockito.doReturn(
172 Json.createObjectBuilder()
173 .add("download_count", prop)
174 .build()
175 ).when(releaseAsset).json();
176 MatcherAssert.assertThat(
177 new ReleaseAsset.Smart(releaseAsset).downloadCount(),
178 Matchers.is(prop)
179 );
180 }
181
182
183
184
185
186 @Test
187 public final void fetchesCreatedAt() throws Exception {
188 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
189 final String prop = "2013-02-27T19:35:32Z";
190 Mockito.doReturn(
191 Json.createObjectBuilder()
192 .add("created_at", prop)
193 .build()
194 ).when(releaseAsset).json();
195 MatcherAssert.assertThat(
196 new ReleaseAsset.Smart(releaseAsset).createdAt(),
197 Matchers.equalTo(new Github.Time(prop).date())
198 );
199 }
200
201
202
203
204
205 @Test
206 public final void fetchesUpdatedAt() throws Exception {
207 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
208 final String prop = "2013-02-27T19:35:32Z";
209 Mockito.doReturn(
210 Json.createObjectBuilder()
211 .add("updated_at", prop)
212 .build()
213 ).when(releaseAsset).json();
214 MatcherAssert.assertThat(
215 new ReleaseAsset.Smart(releaseAsset).updatedAt(),
216 Matchers.equalTo(new Github.Time(prop).date())
217 );
218 }
219
220
221
222
223
224 @Test
225 public final void updatesName() throws Exception {
226 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
227 final String prop = "new_name";
228 new ReleaseAsset.Smart(releaseAsset).name(prop);
229 Mockito.verify(releaseAsset).patch(
230 Json.createObjectBuilder().add("name", prop).build()
231 );
232 }
233
234
235
236
237
238 @Test
239 public final void updatesLabel() throws Exception {
240 final ReleaseAsset releaseAsset = Mockito.mock(ReleaseAsset.class);
241 final String prop = "new_label";
242 new ReleaseAsset.Smart(releaseAsset).label(prop);
243 Mockito.verify(releaseAsset).patch(
244 Json.createObjectBuilder().add("label", prop).build()
245 );
246 }
247 }