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.Coordinates;
33 import com.jcabi.github.Repo;
34 import java.io.IOException;
35 import org.hamcrest.MatcherAssert;
36 import org.hamcrest.Matchers;
37 import org.junit.Test;
38 import org.xembly.Directives;
39
40
41
42
43
44
45 public final class MkRepoCommitTest {
46
47
48
49
50 private static final String SHA1 =
51 "6dcb09b5b57875f334f61aebed695e2e4193db5e";
52
53
54
55 private static final String SHA2 =
56 "51cabb8e759852a6a40a7a2a76ef0afd4beef96d";
57
58
59
60
61
62 @Test
63 public void getRepo() throws IOException {
64 final MkStorage storage = new MkStorage.InFile();
65 final Repo repo = this.repo(storage);
66 MatcherAssert.assertThat(
67 new MkRepoCommit(
68 storage, repo, SHA1
69 ).repo(), Matchers.equalTo(repo)
70 );
71 }
72
73
74
75
76
77 @Test
78 public void getSha() throws IOException {
79 final MkStorage storage = new MkStorage.InFile();
80 MatcherAssert.assertThat(
81 new MkRepoCommit(storage, this.repo(storage), SHA2).sha(),
82 Matchers.equalTo(SHA2)
83 );
84 }
85
86
87
88
89
90
91 @Test
92 public void canCompareInstances() throws Exception {
93 final MkStorage storage = new MkStorage.InFile();
94 final Repo repoa = new MkRepo(
95 storage, "login1",
96 new Coordinates.Simple("test_login1", "test_repo1")
97 );
98 final Repo repob = new MkRepo(
99 storage, "login2",
100 new Coordinates.Simple("test_login2", "test_repo2")
101 );
102 final MkRepoCommit less = new MkRepoCommit(
103 storage, repoa, SHA1
104 );
105 final MkRepoCommit greater = new MkRepoCommit(
106 storage, repob, SHA2
107 );
108 MatcherAssert.assertThat(
109 less.compareTo(greater),
110 Matchers.lessThan(0)
111 );
112 MatcherAssert.assertThat(
113 greater.compareTo(less),
114 Matchers.greaterThan(0)
115 );
116 }
117
118
119
120
121 @Test
122 public void canGetJson() throws Exception {
123 final MkStorage storage = new MkStorage.InFile();
124 storage.apply(
125 new Directives().xpath("/github").add("repos")
126 .add("repo").attr("coords", "test_login/test_repo")
127 .add("commits").add("commit").add("sha").set(SHA1)
128 );
129 final MkRepoCommit repoCommit = new MkRepoCommit(
130 storage, this.repo(storage), SHA1
131 );
132 MatcherAssert.assertThat(
133 repoCommit.json(), Matchers.notNullValue()
134 );
135 }
136
137
138
139
140
141 @Test
142 public void compareEqual() throws Exception {
143 final String sha = "c2c53d66948214258a26ca9ca845d7ac0c17f8e7";
144 final MkStorage storage = new MkStorage.InFile();
145 final Repo repo = this.repo(storage);
146 final MkRepoCommit commit = new MkRepoCommit(storage, repo, sha);
147 final MkRepoCommit other = new MkRepoCommit(storage, repo, sha);
148 MatcherAssert.assertThat(
149 commit.compareTo(other), Matchers.equalTo(0)
150 );
151 MatcherAssert.assertThat(
152 other.compareTo(commit), Matchers.equalTo(0)
153 );
154 }
155
156
157
158
159
160 @Test
161 public void compareDifferent() throws Exception {
162 final MkStorage storage = new MkStorage.InFile();
163 final Repo repo = this.repo(storage);
164 final MkRepoCommit commit = new MkRepoCommit(
165 storage, repo, "6dcd4ce23d88e2ee9568ba546c007c63d9131c1b"
166 );
167 final MkRepoCommit other = new MkRepoCommit(
168 storage, repo, "e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98"
169 );
170 MatcherAssert.assertThat(
171 commit.compareTo(other), Matchers.not(0)
172 );
173 MatcherAssert.assertThat(
174 other.compareTo(commit), Matchers.not(0)
175 );
176 }
177
178
179
180
181
182
183 private Repo repo(final MkStorage storage) {
184 final String login = "test_login";
185 return new MkRepo(
186 storage,
187 login,
188 new Coordinates.Simple(login, "test_repo")
189 );
190 }
191 }