1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.google.common.collect.Lists;
8 import com.jcabi.github.Coordinates;
9 import com.jcabi.github.Language;
10 import com.jcabi.github.Milestones;
11 import com.jcabi.github.Repo;
12 import com.jcabi.github.Repos;
13 import java.io.IOException;
14 import org.hamcrest.MatcherAssert;
15 import org.hamcrest.Matchers;
16 import org.junit.jupiter.api.Test;
17
18
19
20
21
22
23 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
24 final class MkRepoTest {
25
26 @Test
27 void works() throws IOException {
28 final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
29 final Repo repo = repos.create(
30 new Repos.RepoCreate("test5", false)
31 );
32 MatcherAssert.assertThat(
33 "Assertion failed",
34 repo.coordinates(),
35 Matchers.hasToString("jeff/test5")
36 );
37 }
38
39
40
41
42 @Test
43 void returnsMkMilestones() throws IOException {
44 final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
45 final Repo repo = repos.create(
46 new Repos.RepoCreate("test1", false)
47 );
48 final Milestones milestones = repo.milestones();
49 MatcherAssert.assertThat(
50 "Value is null", milestones, Matchers.notNullValue()
51 );
52 }
53
54
55
56
57
58 @Test
59 void fetchCommits() throws IOException {
60 final String user = "testuser";
61 final Repo repo = new MkRepo(
62 new MkStorage.InFile(),
63 user,
64 new Coordinates.Simple(user, "testrepo")
65 );
66 MatcherAssert.assertThat(
67 "Value is null", repo.commits(), Matchers.notNullValue()
68 );
69 }
70
71
72
73
74
75 @Test
76 void fetchBranches() throws IOException {
77 final String user = "testuser";
78 final Repo repo = new MkRepo(
79 new MkStorage.InFile(),
80 user,
81 new Coordinates.Simple(user, "testrepo")
82 );
83 MatcherAssert.assertThat(
84 "Value is null", repo.branches(), Matchers.notNullValue()
85 );
86 }
87
88 @Test
89 void exposesAttributes() throws IOException {
90 final Repo repo = new MkGitHub().randomRepo();
91 MatcherAssert.assertThat(
92 "Value is null",
93 new Repo.Smart(repo).description(),
94 Matchers.notNullValue()
95 );
96 MatcherAssert.assertThat(
97 "Values are not equal",
98 new Repo.Smart(repo).isPrivate(),
99 Matchers.is(true)
100 );
101 }
102
103
104
105
106
107 @Test
108 void fetchStars() throws IOException {
109 final String user = "testuser2";
110 final Repo repo = new MkRepo(
111 new MkStorage.InFile(),
112 user,
113 new Coordinates.Simple(user, "testrepo2")
114 );
115 MatcherAssert.assertThat(
116 "Value is null", repo.stars(), Matchers.notNullValue()
117 );
118 }
119
120
121
122
123
124 @Test
125 void fetchNotifications() throws IOException {
126 final String user = "testuser3";
127 final Repo repo = new MkRepo(
128 new MkStorage.InFile(),
129 user,
130 new Coordinates.Simple(user, "testrepo3")
131 );
132 MatcherAssert.assertThat(
133 "Value is null", repo.notifications(), Matchers.notNullValue()
134 );
135 }
136
137
138
139
140
141 @Test
142 void fetchLanguages() throws IOException {
143 final String user = "testuser4";
144 final Repo repo = new MkRepo(
145 new MkStorage.InFile(),
146 user,
147 new Coordinates.Simple(user, "testrepo4")
148 );
149 final Iterable<Language> languages = repo.languages();
150 MatcherAssert.assertThat(
151 "Value is null", languages, Matchers.notNullValue()
152 );
153 MatcherAssert.assertThat(
154 "Collection size is incorrect",
155 Lists.newArrayList(languages),
156 Matchers.hasSize(3)
157 );
158 }
159
160
161
162
163
164 @Test
165 void retrievesDefaultBranch() throws IOException {
166 final String user = "testuser5";
167 final Repo repo = new MkRepo(
168 new MkStorage.InFile(),
169 user,
170 new Coordinates.Simple(user, "testrepo5")
171 );
172 MatcherAssert.assertThat(
173 "Values are not equal",
174 repo.defaultBranch().name(),
175 Matchers.equalTo("master")
176 );
177 }
178 }