1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.http.request.FakeRequest;
8 import java.io.IOException;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.hamcrest.core.IsEqual;
12 import org.junit.jupiter.api.Test;
13
14
15
16
17
18 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
19 final class RtGitHubTest {
20
21 @Test
22 void retrievesRepos() {
23 final RtGitHub github = new RtGitHub(new FakeRequest());
24 MatcherAssert.assertThat(
25 "Value is null",
26 github.repos(),
27 Matchers.notNullValue()
28 );
29 }
30
31 @Test
32 void retrievesGists() {
33 final RtGitHub github = new RtGitHub(new FakeRequest());
34 MatcherAssert.assertThat(
35 "Value is null",
36 github.gists(),
37 Matchers.notNullValue()
38 );
39 }
40
41 @Test
42 void retrievesUsers() {
43 final RtGitHub github = new RtGitHub(new FakeRequest());
44 MatcherAssert.assertThat(
45 "Value is null",
46 github.users(),
47 Matchers.notNullValue()
48 );
49 }
50
51 @Test
52 void retrievesMetaAsJson() throws IOException {
53 final RtGitHub github = new RtGitHub(
54 new FakeRequest().withBody("{\"meta\":\"blah\"}")
55 );
56 MatcherAssert.assertThat(
57 "Values are not equal",
58 github.meta().getString("meta"),
59 Matchers.equalTo("blah")
60 );
61 }
62
63 @Test
64 void retrievesEmojisAsJson() throws IOException {
65 final RtGitHub github = new RtGitHub(
66 new FakeRequest().withBody(
67 "{ \"emojikey\": \"urlvalue\" }"
68 )
69 );
70 MatcherAssert.assertThat(
71 "Values are not equal",
72 github.emojis().getString("emojikey"),
73 new IsEqual<>("urlvalue")
74 );
75 }
76
77 @Test
78 void retrievesMarkdown() {
79 final RtGitHub github = new RtGitHub(new FakeRequest());
80 MatcherAssert.assertThat(
81 "Value is null",
82 github.markdown(),
83 Matchers.notNullValue()
84 );
85 }
86
87 @Test
88 void retrievesGitignores() {
89 final RtGitHub github = new RtGitHub(new FakeRequest());
90 MatcherAssert.assertThat(
91 "Value is null",
92 github.gitignores(),
93 Matchers.notNullValue()
94 );
95 }
96
97 @Test
98 void testSameTimesAreEqual() {
99 final long time = System.currentTimeMillis();
100 final GitHub.Time first = new GitHub.Time(time);
101 final GitHub.Time second = new GitHub.Time(time);
102 MatcherAssert.assertThat(
103 "Values are not equal",
104 first.toString(),
105 Matchers.equalTo(second.toString())
106 );
107 }
108
109 @Test
110 void testDifferentTimesAreNotEqual() {
111 final GitHub.Time first = new GitHub.Time(System.currentTimeMillis());
112 final GitHub.Time second = new GitHub.Time(
113 System.currentTimeMillis() + 1
114 );
115 MatcherAssert.assertThat(
116 "Values are not equal",
117 first.equals(second),
118 Matchers.is(false)
119 );
120 }
121
122 @Test
123 void equalsToAnotherGitHub() {
124 MatcherAssert.assertThat(
125 "Values are not equal",
126 new RtGitHub(new FakeRequest().header("abc", "cde")),
127 Matchers.not(
128 Matchers.equalTo(
129 new RtGitHub(new FakeRequest().header("fgh", "ikl"))
130 )
131 )
132 );
133 MatcherAssert.assertThat(
134 "Values are not equal",
135 new RtGitHub(new FakeRequest()),
136 Matchers.equalTo(new RtGitHub(new FakeRequest()))
137 );
138 }
139 }