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.aspects.Tv;
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 public class ForkTest {
45
46
47
48
49 @Test
50 public final void fetchesName() throws Exception {
51 final Fork fork = Mockito.mock(Fork.class);
52 final String name = "this is some name";
53 Mockito.doReturn(
54 Json.createObjectBuilder()
55 .add("name", name)
56 .build()
57 ).when(fork).json();
58 MatcherAssert.assertThat(
59 new Fork.Smart(fork).name(),
60 Matchers.is(name)
61 );
62 }
63
64
65
66
67
68 @Test
69 public final void fetchesFullName() throws Exception {
70 final Fork fork = Mockito.mock(Fork.class);
71 final String name = "test full name";
72 Mockito.doReturn(
73 Json.createObjectBuilder()
74 .add("full_name", name)
75 .build()
76 ).when(fork).json();
77 MatcherAssert.assertThat(
78 new Fork.Smart(fork).fullName(),
79 Matchers.is(name)
80 );
81 }
82
83
84
85
86
87 @Test
88 public final void fetchesDescription() throws Exception {
89 final Fork fork = Mockito.mock(Fork.class);
90 final String description = "test description";
91 Mockito.doReturn(
92 Json.createObjectBuilder()
93 .add("description", description)
94 .build()
95 ).when(fork).json();
96 MatcherAssert.assertThat(
97 new Fork.Smart(fork).description(),
98 Matchers.is(description)
99 );
100 }
101
102
103
104
105 @Test
106 public final void fetchesSize() throws Exception {
107 final Fork fork = Mockito.mock(Fork.class);
108 final int prop = Tv.HUNDRED;
109 Mockito.doReturn(
110 Json.createObjectBuilder()
111 .add("size", prop)
112 .build()
113 ).when(fork).json();
114 MatcherAssert.assertThat(
115 new Fork.Smart(fork).size(),
116 Matchers.is(prop)
117 );
118 }
119
120
121
122
123
124 @Test
125 public final void fetchesUrls() throws Exception {
126 final Fork fork = Mockito.mock(Fork.class);
127 final String url = "https://api.github.com/repos/octocat/Hello-World";
128 final String html = "https://github.com/octocat/Hello-World";
129 final String clone = "https://github.com/octocat/Hello-World.git";
130 final String git = "git://github.com/octocat/Hello-World.git";
131 final String ssh = "git@github.com:octocat/Hello-World.git";
132 final String svn = "https://svn.github.com/octocat/Hello-World";
133 final String mirror = "git://git.example.com/octocat/Hello-World";
134 final String homepage = "https://github.com";
135 Mockito.doReturn(
136 Json.createObjectBuilder()
137 .add("url", url)
138 .add("html_url", html)
139 .add("clone_url", clone)
140 .add("git_url", git)
141 .add("ssh_url", ssh)
142 .add("svn_url", svn)
143 .add("mirror_url", mirror)
144 .add("homepage", homepage)
145 .build()
146 ).when(fork).json();
147 final Fork.Smart smart = new Fork.Smart(fork);
148 MatcherAssert.assertThat(
149 smart.url().toString(),
150 Matchers.is(url)
151 );
152 MatcherAssert.assertThat(
153 smart.htmlUrl().toString(),
154 Matchers.is(html)
155 );
156 MatcherAssert.assertThat(
157 smart.cloneUrl().toString(),
158 Matchers.is(clone)
159 );
160 MatcherAssert.assertThat(
161 smart.gitUrl().toString(),
162 Matchers.is(git)
163 );
164 MatcherAssert.assertThat(
165 smart.sshUrl().toString(),
166 Matchers.is(ssh)
167 );
168 MatcherAssert.assertThat(
169 smart.svnUrl().toString(),
170 Matchers.is(svn)
171 );
172 MatcherAssert.assertThat(
173 smart.mirrorUrl().toString(),
174 Matchers.is(mirror)
175 );
176 MatcherAssert.assertThat(
177 smart.homeUrl().toString(),
178 Matchers.is(homepage)
179 );
180 }
181
182
183
184
185
186 @Test
187 public final void fetchesCounts() throws Exception {
188 final Fork fork = Mockito.mock(Fork.class);
189 final int forks = Tv.TEN;
190 final int stargazers = Tv.TWENTY;
191 final int watchers = Tv.THIRTY;
192 Mockito.doReturn(
193 Json.createObjectBuilder()
194 .add("forks_count", forks)
195 .add("stargazers_count", stargazers)
196 .add("watchers_count", watchers)
197 .build()
198 ).when(fork).json();
199 final Fork.Smart smart = new Fork.Smart(fork);
200 MatcherAssert.assertThat(
201 smart.forks(),
202 Matchers.is(forks)
203 );
204 MatcherAssert.assertThat(
205 smart.stargazers(),
206 Matchers.is(stargazers)
207 );
208 MatcherAssert.assertThat(
209 smart.watchers(),
210 Matchers.is(watchers)
211 );
212 }
213
214
215
216
217
218 @Test
219 public final void openIssues() throws Exception {
220 final Fork fork = Mockito.mock(Fork.class);
221 final int openIssues = Tv.TEN;
222 Mockito.doReturn(
223 Json.createObjectBuilder()
224 .add("open_issues_count", openIssues)
225 .build()
226 ).when(fork).json();
227 final Fork.Smart smart = new Fork.Smart(fork);
228 MatcherAssert.assertThat(
229 smart.openIssues(),
230 Matchers.is(openIssues)
231 );
232 }
233
234
235
236
237
238 @Test
239 public final void fetchesDefaultBranches() throws Exception {
240 final Fork fork = Mockito.mock(Fork.class);
241 final String master = "master";
242 Mockito.doReturn(
243 Json.createObjectBuilder()
244 .add("default_branch", master)
245 .build()
246 ).when(fork).json();
247 final Fork.Smart smart = new Fork.Smart(fork);
248 MatcherAssert.assertThat(
249 smart.defaultBranch(),
250 Matchers.is(master)
251 );
252 }
253 }