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;
31
32 import com.jcabi.http.request.FakeRequest;
33 import java.util.Collections;
34 import javax.json.Json;
35 import org.hamcrest.MatcherAssert;
36 import org.hamcrest.Matchers;
37 import org.junit.Test;
38
39
40
41
42
43
44 public final class RtRepoCommitsTest {
45
46
47
48
49 @Test
50 public void returnIterator() {
51 final String sha = "6dcb09b5b57875f334f61aebed695e2e4193db51";
52 final RepoCommits commits = new RtRepoCommits(
53 new FakeRequest().withBody(
54 Json.createArrayBuilder().add(
55
56 Json.createObjectBuilder().add("sha", sha)
57 ).build().toString()
58 ),
59 RtRepoCommitsTest.repo()
60 );
61 MatcherAssert.assertThat(
62 commits.iterate(
63 Collections.<String, String>emptyMap()
64 ).iterator().next().sha(),
65 Matchers.equalTo(sha)
66 );
67 }
68
69
70
71
72 @Test
73 public void getCommit() {
74 final String sha = "6dcb09b5b57875f334f61aebed695e2e4193db52";
75 final RepoCommits commits = new RtRepoCommits(
76 new FakeRequest().withBody(
77 Json.createObjectBuilder()
78 .add("sha", sha)
79 .build()
80 .toString()
81 ),
82 RtRepoCommitsTest.repo()
83 );
84 MatcherAssert.assertThat(commits.get(sha).sha(), Matchers.equalTo(sha));
85 }
86
87
88
89
90 @Test
91 public void comparesCommits() {
92 final RepoCommits commits = new RtRepoCommits(
93 new FakeRequest().withBody(
94 Json.createObjectBuilder()
95 .add("base_commit", Json.createObjectBuilder())
96 .add("commits", Json.createArrayBuilder())
97 .add("files", Json.createArrayBuilder())
98 .build().toString()
99 ),
100 RtRepoCommitsTest.repo()
101 );
102 MatcherAssert.assertThat(
103 commits.compare(
104 "6dcb09b5b57875f334f61aebed695e2e4193db53",
105 "6dcb09b5b57875f334f61aebed695e2e4193db54"
106 ),
107 Matchers.notNullValue(CommitsComparison.class)
108 );
109 }
110
111
112
113
114
115 @Test
116 public void comparesCommitsDiffFormat() throws Exception {
117 final RepoCommits commits = new RtRepoCommits(
118 new FakeRequest().withBody("diff --git"),
119 RtRepoCommitsTest.repo()
120 );
121 MatcherAssert.assertThat(
122 commits.diff(
123 "6dcb09b5b57875f334f61aebed695e2e4193db55",
124 "6dcb09b5b57875f334f61aebed695e2e4193db56"
125 ),
126 Matchers.startsWith("diff")
127 );
128 }
129
130
131
132
133
134 @Test
135 public void comparesCommitsPatchFormat() throws Exception {
136 final RepoCommits commits = new RtRepoCommits(
137 new FakeRequest().withBody(
138 "From 6dcb09b5b57875f33"
139 ),
140 RtRepoCommitsTest.repo()
141 );
142 MatcherAssert.assertThat(
143 commits.patch(
144 "6dcb09b5b57875f334f61aebed695e2e4193db57",
145 "6dcb09b5b57875f334f61aebed695e2e4193db58"
146 ),
147 Matchers.startsWith("From")
148 );
149 }
150
151
152
153
154 @Test
155 public void readCorrectURL() {
156 MatcherAssert.assertThat(
157 new RtRepoCommits(new FakeRequest(), repo())
158 .compare("base", "head").toString(),
159 Matchers.endsWith(
160 "/see-FakeRequest-class/repos/user/repo/compare/base...head"
161 )
162 );
163 }
164
165
166
167
168
169 private static Repo repo() {
170 return new RtGithub().repos()
171 .get(new Coordinates.Simple("user", "repo"));
172 }
173
174 }