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 java.nio.charset.StandardCharsets;
34 import javax.json.Json;
35 import org.hamcrest.MatcherAssert;
36 import org.hamcrest.Matchers;
37 import org.junit.Test;
38 import org.mockito.Mockito;
39
40
41
42
43
44
45
46 @SuppressWarnings("PMD.TooManyMethods")
47 public class ContentTest {
48
49
50
51
52 @Test
53 public final void fetchesType() throws Exception {
54 final Content content = Mockito.mock(Content.class);
55 final String prop = "this is some type";
56 Mockito.doReturn(
57 Json.createObjectBuilder()
58 .add("type", prop)
59 .build()
60 ).when(content).json();
61 MatcherAssert.assertThat(
62 new Content.Smart(content).type(),
63 Matchers.is(prop)
64 );
65 }
66
67
68
69
70
71 @Test
72 public final void fetchesSize() throws Exception {
73 final Content content = Mockito.mock(Content.class);
74 final int prop = 5555;
75 Mockito.doReturn(
76 Json.createObjectBuilder()
77
78 .add("size", prop)
79 .build()
80 ).when(content).json();
81 MatcherAssert.assertThat(
82 new Content.Smart(content).size(),
83
84 Matchers.is(prop)
85 );
86 }
87
88
89
90
91
92 @Test
93 public final void fetchesName() throws Exception {
94 final Content content = Mockito.mock(Content.class);
95 final String prop = "this is some name";
96 Mockito.doReturn(
97 Json.createObjectBuilder()
98 .add("name", prop)
99 .build()
100 ).when(content).json();
101 MatcherAssert.assertThat(
102 new Content.Smart(content).name(),
103 Matchers.is(prop)
104 );
105 }
106
107
108
109
110 @Test
111 public final void fetchesPath() {
112 final Content content = Mockito.mock(Content.class);
113 final String path = "this is some path";
114 Mockito.doReturn(path).when(content).path();
115 MatcherAssert.assertThat(
116 new Content.Smart(content).path(),
117 Matchers.is(path)
118 );
119 }
120
121
122
123
124
125 @Test
126 public final void fetchesSha() throws Exception {
127 final Content content = Mockito.mock(Content.class);
128 final String prop = "this is some sha";
129 Mockito.doReturn(
130 Json.createObjectBuilder()
131 .add("sha", prop)
132 .build()
133 ).when(content).json();
134 MatcherAssert.assertThat(
135 new Content.Smart(content).sha(),
136 Matchers.is(prop)
137 );
138 }
139
140
141
142
143
144 @Test
145 public final void fetchesUrl() throws Exception {
146 final Content content = Mockito.mock(Content.class);
147
148 final String prop = "https://api.github.com/repos/pengwynn/octokit/contents/README.md";
149 Mockito.doReturn(
150 Json.createObjectBuilder()
151 .add("url", prop)
152 .build()
153 ).when(content).json();
154 MatcherAssert.assertThat(
155 new Content.Smart(content).url(),
156 Matchers.is(new URL(prop))
157 );
158 }
159
160
161
162
163
164 @Test
165 public final void fetchesGitUrl() throws Exception {
166 final Content content = Mockito.mock(Content.class);
167
168 final String prop = "https://api.github.com/repos/pengwynn/octokit/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1";
169 Mockito.doReturn(
170 Json.createObjectBuilder()
171 .add("git_url", prop)
172 .build()
173 ).when(content).json();
174 MatcherAssert.assertThat(
175 new Content.Smart(content).gitUrl(),
176 Matchers.is(new URL(prop))
177 );
178 }
179
180
181
182
183
184 @Test
185 public final void fetchesHtmlUrl() throws Exception {
186 final Content content = Mockito.mock(Content.class);
187
188 final String prop = "https://github.com/pengwynn/octokit/blob/master/README.md";
189 Mockito.doReturn(
190 Json.createObjectBuilder()
191 .add("html_url", prop)
192 .build()
193 ).when(content).json();
194 MatcherAssert.assertThat(
195 new Content.Smart(content).htmlUrl(),
196 Matchers.is(new URL(prop))
197 );
198 }
199
200
201
202
203
204 @Test
205 public final void fetchesContent() throws Exception {
206 final Content content = Mockito.mock(Content.class);
207 final String prop = "dGVzdCBlbmNvZGU=";
208 Mockito.doReturn(
209 Json.createObjectBuilder()
210 .add("content", prop)
211 .build()
212 ).when(content).json();
213 MatcherAssert.assertThat(
214 new Content.Smart(content).content(),
215 Matchers.is(prop)
216 );
217 }
218
219
220
221
222
223 @Test
224 public final void fetchesDecoded() throws Exception {
225 final Content content = Mockito.mock(Content.class);
226 final String prop = "dGVzdCBlbmNvZGXigqw=";
227 Mockito.doReturn(
228 Json.createObjectBuilder()
229 .add("content", prop)
230 .build()
231 ).when(content).json();
232 MatcherAssert.assertThat(
233 new String(
234 new Content.Smart(content).decoded(), StandardCharsets.UTF_8
235 ),
236 Matchers.is("test encode\u20ac")
237 );
238 }
239
240
241
242
243 @Test
244 public final void smartCanGetUnderlyingRepo() {
245 final Content content = Mockito.mock(Content.class);
246 final Repo repo = Mockito.mock(Repo.class);
247 Mockito.doReturn(repo).when(content).repo();
248 MatcherAssert.assertThat(
249 new Content.Smart(content).repo(),
250 Matchers.is(repo)
251 );
252 }
253 }