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.jcabi.github.mock.MkGithub;
33 import java.io.IOException;
34 import java.time.ZonedDateTime;
35 import java.util.Map;
36 import javax.json.Json;
37 import org.hamcrest.MatcherAssert;
38 import org.hamcrest.Matchers;
39 import org.junit.Test;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 @SuppressWarnings({"PMD.SuspiciousConstantFieldName", "PMD.VariableNamingConventions"})
64 public final class RepositoryStatisticsTest {
65
66
67
68
69 private static final String FORKS_KEY = "forks_count";
70
71
72
73
74 private static final int FORKS_VALUE = 1;
75
76
77
78
79 private static final String LANGUAGE_KEY = "language";
80
81
82
83
84 private static String LANGUAGE_VALUE = "java";
85
86
87
88
89 private static String STARGAZERS_KEY = "stargazers_count";
90
91
92
93
94 private static int STARGAZERS_VALUE = 2;
95
96
97
98
99 private static String WATCHERS_KEY = "watchers_count";
100
101
102
103
104 private static int WATCHERS_VALUE = 3;
105
106
107
108
109 private static String SIZE_KEY = "size";
110
111
112
113
114 private static int SIZE_VALUE = 4;
115
116
117
118
119 private static String ISSUES_KEY = "open_issues_count";
120
121
122
123
124 private static int ISSUES_VALUE = 5;
125
126
127
128
129 private static String CREATED_KEY = "created_at";
130
131
132
133
134 private static String CREATED_VALUE = "2011-01-26T19:14:43Z";
135
136
137
138
139 private static String UPDATED_KEY = "updated_at";
140
141
142
143
144 private static String UPDATED_VALUE = "2012-01-26T19:14:43Z";
145
146
147
148
149
150 @Test
151 public void retrievesBasicStatisticsFromRepo()
152 throws IOException {
153 MatcherAssert.assertThat(
154 "We expect to have basic statistics from repo",
155 new RepositoryStatistics(this.repo()).toMap(),
156 Matchers.<Map<String, ?>>allOf(
157 Matchers.hasEntry(
158 RepositoryStatisticsTest.LANGUAGE_KEY,
159 RepositoryStatisticsTest.LANGUAGE_VALUE
160 ),
161 Matchers.hasEntry(
162 RepositoryStatisticsTest.FORKS_KEY,
163 String.valueOf(
164 RepositoryStatisticsTest.FORKS_VALUE
165 )
166 ),
167 Matchers.hasEntry(
168 RepositoryStatisticsTest.STARGAZERS_KEY,
169 String.valueOf(
170 RepositoryStatisticsTest.STARGAZERS_VALUE
171 )
172 ),
173 Matchers.hasEntry(
174 RepositoryStatisticsTest.WATCHERS_KEY,
175 String.valueOf(
176 RepositoryStatisticsTest.WATCHERS_VALUE
177 )
178 ),
179 Matchers.hasEntry(
180 RepositoryStatisticsTest.SIZE_KEY,
181 String.valueOf(
182 RepositoryStatisticsTest.SIZE_VALUE
183 )
184 ),
185 Matchers.hasEntry(
186 RepositoryStatisticsTest.ISSUES_KEY,
187 String.valueOf(
188 RepositoryStatisticsTest.ISSUES_VALUE
189 )
190 ),
191 Matchers.hasEntry(
192 RepositoryStatisticsTest.CREATED_KEY,
193 RepositoryStatisticsTest.CREATED_VALUE
194 ),
195 Matchers.hasEntry(
196 RepositoryStatisticsTest.UPDATED_KEY,
197 RepositoryStatisticsTest.UPDATED_VALUE
198 )
199 )
200 );
201 }
202
203
204
205
206
207 @Test
208 public void retrievesSmartStatistics() throws IOException {
209 final RepositoryStatistics.Smart smart =
210 new RepositoryStatistics.Smart(this.repo());
211 MatcherAssert.assertThat(
212 "Forks should be equal to 1",
213 smart.forks(),
214 Matchers.equalTo(
215 RepositoryStatisticsTest.FORKS_VALUE
216 )
217 );
218 MatcherAssert.assertThat(
219 "Stargazers should be equal to 2",
220 smart.stargazers(),
221 Matchers.equalTo(
222 RepositoryStatisticsTest.STARGAZERS_VALUE
223 )
224 );
225 MatcherAssert.assertThat(
226 "Watchers should be equal to 3",
227 smart.watchers(),
228 Matchers.equalTo(
229 RepositoryStatisticsTest.WATCHERS_VALUE
230 )
231 );
232 MatcherAssert.assertThat(
233 "Size should be equal to 4",
234 smart.size(),
235 Matchers.equalTo(
236 RepositoryStatisticsTest.SIZE_VALUE
237 )
238 );
239 MatcherAssert.assertThat(
240 "Issues should be equal to 5",
241 smart.openIssues(),
242 Matchers.equalTo(
243 RepositoryStatisticsTest.ISSUES_VALUE
244 )
245 );
246 MatcherAssert.assertThat(
247 "Created date should be equal to 2011-01-26T19:14:43Z",
248 smart.created(),
249 Matchers.equalTo(
250 ZonedDateTime.parse(
251 RepositoryStatisticsTest.CREATED_VALUE
252 )
253 )
254 );
255 }
256
257
258
259
260
261
262 private Repo repo() throws IOException {
263 return new MkGithub()
264 .repos()
265 .create(
266 new Repos.RepoCreate("volodya-lombrozo", false)
267 .with(
268 RepositoryStatisticsTest.LANGUAGE_KEY,
269 Json.createValue(
270 RepositoryStatisticsTest.LANGUAGE_VALUE
271 )
272 )
273 .with(
274 RepositoryStatisticsTest.FORKS_KEY,
275 Json.createValue(
276 RepositoryStatisticsTest.FORKS_VALUE
277 )
278 )
279 .with(
280 RepositoryStatisticsTest.STARGAZERS_KEY,
281 Json.createValue(
282 RepositoryStatisticsTest.STARGAZERS_VALUE
283 )
284 )
285 .with(
286 RepositoryStatisticsTest.WATCHERS_KEY,
287 Json.createValue(
288 RepositoryStatisticsTest.WATCHERS_VALUE
289 )
290 )
291 .with(
292 RepositoryStatisticsTest.SIZE_KEY,
293 Json.createValue(
294 RepositoryStatisticsTest.SIZE_VALUE
295 )
296 )
297 .with(
298 RepositoryStatisticsTest.ISSUES_KEY,
299 Json.createValue(
300 RepositoryStatisticsTest.ISSUES_VALUE
301 )
302 )
303 .with(
304 RepositoryStatisticsTest.CREATED_KEY,
305 Json.createValue(
306 RepositoryStatisticsTest.CREATED_VALUE
307 )
308 )
309 .with(
310 RepositoryStatisticsTest.UPDATED_KEY,
311 Json.createValue(
312 RepositoryStatisticsTest.UPDATED_VALUE
313 )
314 )
315 );
316 }
317 }