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.github.OAuthScope.Scope;
33 import com.jcabi.immutable.ArrayMap;
34 import java.util.ArrayList;
35 import java.util.Iterator;
36 import java.util.List;
37 import org.hamcrest.MatcherAssert;
38 import org.hamcrest.Matchers;
39 import org.junit.Test;
40
41
42
43
44
45
46
47
48
49
50
51
52 @OAuthScope(Scope.REPO)
53 public class RtRepoCommitsITCase {
54
55
56
57
58
59 @Test
60 public final void fetchCommits() throws Exception {
61 final Iterator<RepoCommit> iterator =
62 RtRepoCommitsITCase.repo().commits().iterate(
63 new ArrayMap<String, String>()
64 .with("since", "2014-01-26T00:00:00Z")
65 .with("until", "2014-01-27T00:00:00Z")
66 ).iterator();
67 final List<String> shas = new ArrayList<String>(5);
68 shas.add("1aa4af45aa2c56421c3d911a0a06da513a7316a0");
69 shas.add("940dd5081fada0ead07762933036bf68a005cc40");
70 shas.add("05940dbeaa6124e4a87d9829fb2fce80b713dcbe");
71 shas.add("51cabb8e759852a6a40a7a2a76ef0afd4beef96d");
72 shas.add("11bd4d527236f9cb211bc6667df06fde075beded");
73 int found = 0;
74 while (iterator.hasNext()) {
75 if (shas.contains(iterator.next().sha())) {
76 found += 1;
77 }
78 }
79 MatcherAssert.assertThat(
80 found,
81 Matchers.equalTo(shas.size())
82 );
83 }
84
85
86
87
88
89 @Test
90 public final void compareCommitsPatch() throws Exception {
91 final String patch = RtRepoCommitsITCase.repo().commits().patch(
92 "5339b8e35b",
93 "9b2e6efde9"
94 );
95 MatcherAssert.assertThat(
96 patch,
97 Matchers.startsWith(
98 "From 9b2e6efde94fabec5876dc481b38811e8b4e992f"
99 )
100 );
101 MatcherAssert.assertThat(
102 patch,
103 Matchers.containsString(
104 "Issue #430 RepoCommit interface was added"
105 )
106 );
107 }
108
109
110
111
112
113 @Test
114 public final void compareCommitsDiff() throws Exception {
115 final String diff = RtRepoCommitsITCase.repo().commits().diff(
116 "2b3814e",
117 "b828dfa"
118 );
119 MatcherAssert.assertThat(
120 diff,
121 Matchers.startsWith("diff --git")
122 );
123 }
124
125
126
127
128
129 @Test
130 public final void getCommit() throws Exception {
131 final String sha = "94e4216";
132 MatcherAssert.assertThat(
133 RtRepoCommitsITCase.repo().commits().get(sha).sha(),
134 Matchers.equalTo(sha)
135 );
136 }
137
138
139
140
141
142 private static Repo repo() {
143 return new GithubIT().connect().repos().get(
144 new Coordinates.Simple("jcabi", "jcabi-github")
145 );
146 }
147 }