1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.immutable.ArrayMap;
8 import java.io.IOException;
9 import java.util.ArrayList;
10 import java.util.Iterator;
11 import java.util.List;
12 import org.hamcrest.MatcherAssert;
13 import org.hamcrest.Matchers;
14 import org.junit.jupiter.api.Test;
15
16
17
18
19
20
21
22
23 @OAuthScope(OAuthScope.Scope.REPO)
24 final class RtRepoCommitsITCase {
25
26 @Test
27 void fetchCommits() {
28 final Iterator<RepoCommit> iterator =
29 RtRepoCommitsITCase.repo().commits().iterate(
30 new ArrayMap<String, String>()
31 .with("since", "2014-01-26T00:00:00Z")
32 .with("until", "2014-01-27T00:00:00Z")
33 ).iterator();
34 final List<String> shas = new ArrayList<>(5);
35 shas.add("1aa4af45aa2c56421c3d911a0a06da513a7316a0");
36 shas.add("940dd5081fada0ead07762933036bf68a005cc40");
37 shas.add("05940dbeaa6124e4a87d9829fb2fce80b713dcbe");
38 shas.add("51cabb8e759852a6a40a7a2a76ef0afd4beef96d");
39 shas.add("11bd4d527236f9cb211bc6667df06fde075beded");
40 int found = 0;
41 while (iterator.hasNext()) {
42 if (shas.contains(iterator.next().sha())) {
43 found += 1;
44 }
45 }
46 MatcherAssert.assertThat(
47 "Values are not equal",
48 found,
49 Matchers.equalTo(shas.size())
50 );
51 }
52
53 @Test
54 void compareCommitsPatch() throws IOException {
55 final String patch = RtRepoCommitsITCase.repo().commits().patch(
56 "5339b8e35b",
57 "9b2e6efde9"
58 );
59 MatcherAssert.assertThat(
60 "String does not start with expected value",
61 patch,
62 Matchers.startsWith(
63 "From 9b2e6efde94fabec5876dc481b38811e8b4e992f"
64 )
65 );
66 MatcherAssert.assertThat(
67 "String does not contain expected value",
68 patch,
69 Matchers.containsString(
70 "Issue #430 RepoCommit interface was added"
71 )
72 );
73 }
74
75 @Test
76 void compareCommitsDiff() throws IOException {
77 final String diff = RtRepoCommitsITCase.repo().commits().diff(
78 "2b3814e",
79 "b828dfa"
80 );
81 MatcherAssert.assertThat(
82 "String does not start with expected value",
83 diff,
84 Matchers.startsWith("diff --git")
85 );
86 }
87
88 @Test
89 void getCommit() {
90 final String sha = "94e4216";
91 MatcherAssert.assertThat(
92 "Values are not equal",
93 RtRepoCommitsITCase.repo().commits().get(sha).sha(),
94 Matchers.equalTo(sha)
95 );
96 }
97
98
99
100
101
102 private static Repo repo() {
103 return GitHubIT.connect().repos().get(
104 new Coordinates.Simple("jcabi", "jcabi-github")
105 );
106 }
107 }