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.mock;
31
32 import com.jcabi.github.Repo;
33 import com.jcabi.github.Repos;
34 import org.hamcrest.MatcherAssert;
35 import org.hamcrest.Matchers;
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.junit.rules.ExpectedException;
39
40
41
42
43
44
45
46 public final class MkReposTest {
47
48
49
50
51
52 @Rule
53 @SuppressWarnings("deprecation")
54 public transient ExpectedException thrown = ExpectedException.none();
55
56
57
58
59
60 @Test
61 public void createsRepository() throws Exception {
62 final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
63 final Repo repo = MkReposTest.repo(repos, "test", "test repo");
64 MatcherAssert.assertThat(
65 repo.coordinates(),
66 Matchers.hasToString("jeff/test")
67 );
68 }
69
70
71
72
73
74 @Test
75 public void createsRepositoryWithOrganization() throws Exception {
76 final Repos repos = new MkRepos(new MkStorage.InFile(), "john");
77 final Repo repo = MkReposTest.repoWithOrg(repos, "test", "myorg");
78 MatcherAssert.assertThat(
79 repo.coordinates(),
80 Matchers.hasToString("/orgs/myorg/repos/test")
81 );
82 }
83
84
85
86
87
88 @Test
89 public void createsRepositoryWithDetails() throws Exception {
90 final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
91 final Repo repo = MkReposTest.repo(repos, "hello", "my test repo");
92 MatcherAssert.assertThat(
93 new Repo.Smart(repo).description(),
94 Matchers.startsWith("my test")
95 );
96 }
97
98
99
100
101
102 @Test
103 public void removesRepo() throws Exception {
104 final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
105 final Repo repo = MkReposTest.repo(repos, "remove-me", "remove repo");
106 MatcherAssert.assertThat(
107 repos.get(repo.coordinates()),
108 Matchers.notNullValue()
109 );
110 }
111
112
113
114
115
116 @Test
117 public void iterateRepos() throws Exception {
118 final String since = "1";
119 final Repos repos = new MkRepos(new MkStorage.InFile(), "tom");
120 MkReposTest.repo(repos, since, "repo 1");
121 MkReposTest.repo(repos, "2", "repo 2");
122 MatcherAssert.assertThat(
123 repos.iterate(since),
124 Matchers.<Repo>iterableWithSize(2)
125 );
126 }
127
128
129
130
131
132 @Test
133 public void createsPrivateRepo() throws Exception {
134 final boolean priv = true;
135 MatcherAssert.assertThat(
136 new Repo.Smart(
137 new MkGithub().repos().create(
138 new Repos.RepoCreate("test", priv)
139 )
140 ).isPrivate(),
141 Matchers.is(priv)
142 );
143 }
144
145
146
147
148
149 @Test
150 public void existsRepo() throws Exception {
151 final Repos repos = new MkRepos(new MkStorage.InFile(), "john");
152 final Repo repo = MkReposTest.repo(repos, "exist", "existing repo");
153 MatcherAssert.assertThat(
154 repos.exists(repo.coordinates()),
155 Matchers.is(true)
156 );
157 }
158
159
160
161
162
163
164
165
166
167 private static Repo repo(final Repos repos, final String name,
168 final String desc) throws Exception {
169 return repos.create(
170 new Repos.RepoCreate(name, false).withDescription(desc)
171 );
172 }
173
174
175
176
177
178
179
180
181
182 private static Repo repoWithOrg(final Repos repos, final String name,
183 final String org) throws Exception {
184 return repos.create(
185 new Repos.RepoCreate(name, false).withOrganization(org)
186 );
187 }
188 }