1 /**
2 * Copyright (c) 2013-2023, jcabi.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met: 1) Redistributions of source code must retain the above
8 * copyright notice, this list of conditions and the following
9 * disclaimer. 2) Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution. 3) Neither the name of the jcabi.com nor
13 * the names of its contributors may be used to endorse or promote
14 * products derived from this software without specific prior written
15 * permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package com.jcabi.github;
31
32 import com.jcabi.http.request.FakeRequest;
33 import org.hamcrest.MatcherAssert;
34 import org.hamcrest.Matchers;
35 import org.hamcrest.core.IsEqual;
36 import org.junit.Test;
37
38 /**
39 * Test case for {@link RtGithub}.
40 *
41 * @author Carlos Miranda (miranda.cma@gmail.com)
42 * @version $Id: 4f82aad3e7fdfad078727b2a4f9096af58a95e3d $
43 */
44 public final class RtGithubTest {
45
46 /**
47 * RtGithub can retrieve its repos.
48 *
49 */
50 @Test
51 public void retrievesRepos() {
52 final RtGithub github = new RtGithub(new FakeRequest());
53 MatcherAssert.assertThat(
54 github.repos(),
55 Matchers.notNullValue()
56 );
57 }
58
59 /**
60 * RtGithub can retrieve its gists.
61 *
62 */
63 @Test
64 public void retrievesGists() {
65 final RtGithub github = new RtGithub(new FakeRequest());
66 MatcherAssert.assertThat(
67 github.gists(),
68 Matchers.notNullValue()
69 );
70 }
71
72 /**
73 * RtGithub can retrieve users.
74 *
75 */
76 @Test
77 public void retrievesUsers() {
78 final RtGithub github = new RtGithub(new FakeRequest());
79 MatcherAssert.assertThat(
80 github.users(),
81 Matchers.notNullValue()
82 );
83 }
84
85 /**
86 * RtGithub can retrieve meta information in JSON format.
87 *
88 * @throws Exception if a problem occurs.
89 */
90 @Test
91 public void retrievesMetaAsJson() throws Exception {
92 final RtGithub github = new RtGithub(
93 new FakeRequest().withBody("{\"meta\":\"blah\"}")
94 );
95 MatcherAssert.assertThat(
96 github.meta().getString("meta"),
97 Matchers.equalTo("blah")
98 );
99 }
100
101 /**
102 * RtGithub can retrieve emoji information in JSON format.
103 *
104 * @throws Exception if a problem occurs.
105 */
106 @Test
107 public void retrievesEmojisAsJson() throws Exception {
108 final RtGithub github = new RtGithub(
109 new FakeRequest().withBody(
110 "{ \"emojikey\": \"urlvalue\" }"
111 )
112 );
113 MatcherAssert.assertThat(
114 github.emojis().getString("emojikey"),
115 new IsEqual<>("urlvalue")
116 );
117 }
118
119 /**
120 * RtGithub can retrieve the markdown.
121 *
122 */
123 @Test
124 public void retrievesMarkdown() {
125 final RtGithub github = new RtGithub(new FakeRequest());
126 MatcherAssert.assertThat(
127 github.markdown(),
128 Matchers.notNullValue()
129 );
130 }
131
132 /**
133 * RtGithub can retrieve the gitignores.
134 */
135 @Test
136 public void retrievesGitignores() {
137 final RtGithub github = new RtGithub(new FakeRequest());
138 MatcherAssert.assertThat(
139 github.gitignores(),
140 Matchers.notNullValue()
141 );
142 }
143
144 /**
145 * Github.Time can compare two same Times successfully.
146 */
147 @Test
148 public void testSameTimesAreEqual() {
149 final long time = System.currentTimeMillis();
150 final Github.Time first = new Github.Time(time);
151 final Github.Time second = new Github.Time(time);
152 MatcherAssert.assertThat(
153 first.equals(second),
154 Matchers.is(true)
155 );
156 }
157
158 /**
159 * Github.Time can compare two different Times successfully.
160 */
161 @Test
162 public void testDifferentTimesAreNotEqual() {
163 final Github.Time first = new Github.Time(System.currentTimeMillis());
164 final Github.Time second = new Github.Time(
165 System.currentTimeMillis() + 1
166 );
167 MatcherAssert.assertThat(
168 first.equals(second),
169 Matchers.is(false)
170 );
171 }
172
173 /**
174 * RtGithub can compare itself with another object.
175 */
176 @Test
177 public void equalsToAnotherGithub() {
178 MatcherAssert.assertThat(
179 new RtGithub(new FakeRequest().header("abc", "cde")),
180 Matchers.not(
181 Matchers.equalTo(
182 new RtGithub(new FakeRequest().header("fgh", "ikl"))
183 )
184 )
185 );
186 MatcherAssert.assertThat(
187 new RtGithub(new FakeRequest()),
188 Matchers.equalTo(new RtGithub(new FakeRequest()))
189 );
190 }
191 }