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