View Javadoc
1   /**
2    * Copyright (c) 2013-2022, 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: 12ee995f4ef3023fb888617ff48ebd45789ee844 $
43   */
44  public final class RtGithubTest {
45  
46      /**
47       * RtGithub can retrieve its repos.
48       *
49       * @throws Exception if a problem occurs.
50       */
51      @Test
52      public void retrievesRepos() throws Exception {
53          final RtGithub github = new RtGithub(new FakeRequest());
54          MatcherAssert.assertThat(
55              github.repos(),
56              Matchers.notNullValue()
57          );
58      }
59  
60      /**
61       * RtGithub can retrieve its gists.
62       *
63       * @throws Exception if a problem occurs.
64       */
65      @Test
66      public void retrievesGists() throws Exception {
67          final RtGithub github = new RtGithub(new FakeRequest());
68          MatcherAssert.assertThat(
69              github.gists(),
70              Matchers.notNullValue()
71          );
72      }
73  
74      /**
75       * RtGithub can retrieve users.
76       *
77       * @throws Exception if a problem occurs.
78       */
79      @Test
80      public void retrievesUsers() throws Exception {
81          final RtGithub github = new RtGithub(new FakeRequest());
82          MatcherAssert.assertThat(
83              github.users(),
84              Matchers.notNullValue()
85          );
86      }
87  
88      /**
89       * RtGithub can retrieve meta information in JSON format.
90       *
91       * @throws Exception if a problem occurs.
92       */
93      @Test
94      public void retrievesMetaAsJson() throws Exception {
95          final RtGithub github = new RtGithub(
96              new FakeRequest().withBody("{\"meta\":\"blah\"}")
97          );
98          MatcherAssert.assertThat(
99              github.meta().getString("meta"),
100             Matchers.equalTo("blah")
101         );
102     }
103 
104     /**
105      * RtGithub can retrieve emoji information in JSON format.
106      *
107      * @throws Exception if a problem occurs.
108      */
109     @Test
110     public void retrievesEmojisAsJson() throws Exception {
111         final RtGithub github = new RtGithub(
112             new FakeRequest().withBody(
113             "{ \"emojikey\": \"urlvalue\" }"
114             )
115         );
116         MatcherAssert.assertThat(
117             github.emojis().getString("emojikey"),
118             new IsEqual<>("urlvalue")
119         );
120     }
121 
122     /**
123      * RtGithub can retrieve the markdown.
124      *
125      * @throws Exception if a problem occurs.
126      */
127     @Test
128     public void retrievesMarkdown() throws Exception {
129         final RtGithub github = new RtGithub(new FakeRequest());
130         MatcherAssert.assertThat(
131             github.markdown(),
132             Matchers.notNullValue()
133         );
134     }
135 
136     /**
137      * RtGithub can retrieve the gitignores.
138      * @throws Exception if a problem occurs.
139      */
140     @Test
141     public void retrievesGitignores() throws Exception {
142         final RtGithub github = new RtGithub(new FakeRequest());
143         MatcherAssert.assertThat(
144             github.gitignores(),
145             Matchers.notNullValue()
146         );
147     }
148 
149     /**
150      * Github.Time can compare two same Times successfully.
151      */
152     @Test
153     public void testSameTimesAreEqual() {
154         final long time = System.currentTimeMillis();
155         final Github.Time first = new Github.Time(time);
156         final Github.Time second = new Github.Time(time);
157         MatcherAssert.assertThat(
158             first.equals(second),
159             Matchers.is(true)
160         );
161     }
162 
163     /**
164      * Github.Time can compare two different Times successfully.
165      */
166     @Test
167     public void testDifferentTimesAreNotEqual() {
168         final Github.Time first = new Github.Time(System.currentTimeMillis());
169         final Github.Time second = new Github.Time(
170             System.currentTimeMillis() + 1
171         );
172         MatcherAssert.assertThat(
173             first.equals(second),
174             Matchers.is(false)
175         );
176     }
177 
178     /**
179      * RtGithub can compare itself with another object.
180      * @throws Exception if a problem occurs.
181      */
182     @Test
183     public void equalsToAnotherGithub() throws Exception {
184         MatcherAssert.assertThat(
185             new RtGithub(new FakeRequest().header("abc", "cde")),
186             Matchers.not(
187                 Matchers.equalTo(
188                     new RtGithub(new FakeRequest().header("fgh", "ikl"))
189                 )
190             )
191         );
192         MatcherAssert.assertThat(
193             new RtGithub(new FakeRequest()),
194             Matchers.equalTo(new RtGithub(new FakeRequest()))
195         );
196     }
197 }