1
2
3
4
5 package com.jcabi.github;
6
7 import jakarta.json.Json;
8 import java.io.IOException;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.junit.jupiter.api.Test;
12 import org.mockito.Mockito;
13
14
15
16
17
18 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
19 final class ForkTest {
20 @Test
21 void fetchesName() throws IOException {
22 final Fork fork = Mockito.mock(Fork.class);
23 final String name = "this is some name";
24 Mockito.doReturn(
25 Json.createObjectBuilder()
26 .add("name", name)
27 .build()
28 ).when(fork).json();
29 MatcherAssert.assertThat(
30 "Values are not equal",
31 new Fork.Smart(fork).name(),
32 Matchers.is(name)
33 );
34 }
35
36 @Test
37 void fetchesFullName() throws IOException {
38 final Fork fork = Mockito.mock(Fork.class);
39 final String name = "test full name";
40 Mockito.doReturn(
41 Json.createObjectBuilder()
42 .add("full_name", name)
43 .build()
44 ).when(fork).json();
45 MatcherAssert.assertThat(
46 "Values are not equal",
47 new Fork.Smart(fork).fullName(),
48 Matchers.is(name)
49 );
50 }
51
52 @Test
53 void fetchesDescription() throws IOException {
54 final Fork fork = Mockito.mock(Fork.class);
55 final String description = "test description";
56 Mockito.doReturn(
57 Json.createObjectBuilder()
58 .add("description", description)
59 .build()
60 ).when(fork).json();
61 MatcherAssert.assertThat(
62 "Values are not equal",
63 new Fork.Smart(fork).description(),
64 Matchers.is(description)
65 );
66 }
67
68 @Test
69 void fetchesSize() throws IOException {
70 final Fork fork = Mockito.mock(Fork.class);
71 final int prop = 100;
72 Mockito.doReturn(
73 Json.createObjectBuilder()
74 .add("size", prop)
75 .build()
76 ).when(fork).json();
77 MatcherAssert.assertThat(
78 "Values are not equal",
79 new Fork.Smart(fork).size(),
80 Matchers.is(prop)
81 );
82 }
83
84 @Test
85 void fetchesUrls() throws IOException {
86 final Fork fork = Mockito.mock(Fork.class);
87 final String url = "https://api.github.com/repos/octocat/Hello-World";
88 final String html = "https://github.com/octocat/Hello-World";
89 final String clone = "https://github.com/octocat/Hello-World.git";
90 final String git = "git://github.com/octocat/Hello-World.git";
91 final String ssh = "git@github.com:octocat/Hello-World.git";
92 final String svn = "https://svn.github.com/octocat/Hello-World";
93 final String mirror = "git://git.example.com/octocat/Hello-World";
94 final String homepage = "https://github.com";
95 Mockito.doReturn(
96 Json.createObjectBuilder()
97 .add("url", url)
98 .add("html_url", html)
99 .add("clone_url", clone)
100 .add("git_url", git)
101 .add("ssh_url", ssh)
102 .add("svn_url", svn)
103 .add("mirror_url", mirror)
104 .add("homepage", homepage)
105 .build()
106 ).when(fork).json();
107 final Fork.Smart smart = new Fork.Smart(fork);
108 MatcherAssert.assertThat(
109 "Values are not equal",
110 smart.url().toString(),
111 Matchers.is(url)
112 );
113 MatcherAssert.assertThat(
114 "Values are not equal",
115 smart.htmlUrl().toString(),
116 Matchers.is(html)
117 );
118 MatcherAssert.assertThat(
119 "Values are not equal",
120 smart.cloneUrl().toString(),
121 Matchers.is(clone)
122 );
123 MatcherAssert.assertThat(
124 "Values are not equal",
125 smart.gitUrl().toString(),
126 Matchers.is(git)
127 );
128 MatcherAssert.assertThat(
129 "Values are not equal",
130 smart.sshUrl().toString(),
131 Matchers.is(ssh)
132 );
133 MatcherAssert.assertThat(
134 "Values are not equal",
135 smart.svnUrl().toString(),
136 Matchers.is(svn)
137 );
138 MatcherAssert.assertThat(
139 "Values are not equal",
140 smart.mirrorUrl().toString(),
141 Matchers.is(mirror)
142 );
143 MatcherAssert.assertThat(
144 "Values are not equal",
145 smart.homeUrl().toString(),
146 Matchers.is(homepage)
147 );
148 }
149
150
151
152
153
154 @Test
155 void fetchesCounts() throws IOException {
156 final Fork fork = Mockito.mock(Fork.class);
157 final int forks = 10;
158 final int stargazers = 20;
159 final int watchers = 30;
160 Mockito.doReturn(
161 Json.createObjectBuilder()
162 .add("forks_count", forks)
163 .add("stargazers_count", stargazers)
164 .add("watchers_count", watchers)
165 .build()
166 ).when(fork).json();
167 final Fork.Smart smart = new Fork.Smart(fork);
168 MatcherAssert.assertThat(
169 "Values are not equal",
170 smart.forks(),
171 Matchers.is(forks)
172 );
173 MatcherAssert.assertThat(
174 "Values are not equal",
175 smart.stargazers(),
176 Matchers.is(stargazers)
177 );
178 MatcherAssert.assertThat(
179 "Values are not equal",
180 smart.watchers(),
181 Matchers.is(watchers)
182 );
183 }
184
185 @Test
186 void openIssues() throws IOException {
187 final Fork fork = Mockito.mock(Fork.class);
188 final int issues = 10;
189 Mockito.doReturn(
190 Json.createObjectBuilder()
191 .add("open_issues_count", issues)
192 .build()
193 ).when(fork).json();
194 final Fork.Smart smart = new Fork.Smart(fork);
195 MatcherAssert.assertThat(
196 "Values are not equal",
197 smart.openIssues(),
198 Matchers.is(issues)
199 );
200 }
201
202 @Test
203 void fetchesDefaultBranches() throws IOException {
204 final Fork fork = Mockito.mock(Fork.class);
205 final String master = "master";
206 Mockito.doReturn(
207 Json.createObjectBuilder()
208 .add("default_branch", master)
209 .build()
210 ).when(fork).json();
211 final Fork.Smart smart = new Fork.Smart(fork);
212 MatcherAssert.assertThat(
213 "Values are not equal",
214 smart.defaultBranch(),
215 Matchers.is(master)
216 );
217 }
218 }