1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.jcabi.github.Repo;
8 import com.jcabi.github.Repos;
9 import java.io.IOException;
10 import org.hamcrest.MatcherAssert;
11 import org.hamcrest.Matchers;
12 import org.junit.jupiter.api.Test;
13
14
15
16
17
18
19 final class MkReposTest {
20
21
22
23
24
25 @Test
26 void createsRepository() throws Exception {
27 final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
28 final Repo repo = MkReposTest.repo(repos, "test", "test repo");
29 MatcherAssert.assertThat(
30 "Assertion failed",
31 repo.coordinates(),
32 Matchers.hasToString("jeff/test")
33 );
34 }
35
36
37
38
39
40 @Test
41 void createsRepositoryWithOrganization() throws Exception {
42 final Repos repos = new MkRepos(new MkStorage.InFile(), "john");
43 final Repo repo = MkReposTest.repoWithOrg(repos, "test", "myorg");
44 MatcherAssert.assertThat(
45 "Assertion failed",
46 repo.coordinates(),
47 Matchers.hasToString("/orgs/myorg/repos/test")
48 );
49 }
50
51
52
53
54
55 @Test
56 void createsRepositoryWithDetails() throws Exception {
57 final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
58 final Repo repo = MkReposTest.repo(repos, "hello", "my test repo");
59 MatcherAssert.assertThat(
60 "String does not start with expected value",
61 new Repo.Smart(repo).description(),
62 Matchers.startsWith("my test")
63 );
64 }
65
66
67
68
69
70 @Test
71 void removesRepo() throws Exception {
72 final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
73 final Repo repo = MkReposTest.repo(repos, "remove-me", "remove repo");
74 MatcherAssert.assertThat(
75 "Value is null",
76 repos.get(repo.coordinates()),
77 Matchers.notNullValue()
78 );
79 }
80
81
82
83
84
85 @Test
86 void iterateRepos() throws Exception {
87 final String since = "1";
88 final Repos repos = new MkRepos(new MkStorage.InFile(), "tom");
89 MkReposTest.repo(repos, since, "repo 1");
90 MkReposTest.repo(repos, "2", "repo 2");
91 MatcherAssert.assertThat(
92 "Collection size is incorrect",
93 repos.iterate(since),
94 Matchers.iterableWithSize(2)
95 );
96 }
97
98 @Test
99 void createsPrivateRepo() throws IOException {
100 final boolean priv = true;
101 MatcherAssert.assertThat(
102 "Values are not equal",
103 new Repo.Smart(
104 new MkGitHub().repos().create(
105 new Repos.RepoCreate("test", priv)
106 )
107 ).isPrivate(),
108 Matchers.is(priv)
109 );
110 }
111
112
113
114
115
116 @Test
117 void existsRepo() throws Exception {
118 final Repos repos = new MkRepos(new MkStorage.InFile(), "john");
119 final Repo repo = MkReposTest.repo(repos, "exist", "existing repo");
120 MatcherAssert.assertThat(
121 "Values are not equal",
122 repos.exists(repo.coordinates()),
123 Matchers.is(true)
124 );
125 }
126
127
128
129
130
131
132
133
134 private static Repo repo(final Repos repos, final String name,
135 final String desc) throws IOException {
136 return repos.create(
137 new Repos.RepoCreate(name, false).withDescription(desc)
138 );
139 }
140
141
142
143
144
145
146
147
148 private static Repo repoWithOrg(final Repos repos, final String name,
149 final String org) throws IOException {
150 return repos.create(
151 new Repos.RepoCreate(name, false).withOrganization(org)
152 );
153 }
154 }