1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.jcabi.github.Coordinates;
8 import java.io.IOException;
9 import java.util.Arrays;
10 import java.util.Collections;
11 import org.hamcrest.MatcherAssert;
12 import org.hamcrest.Matchers;
13 import org.junit.jupiter.api.Test;
14
15
16
17
18
19 final class MkRepoCommitsTest {
20
21
22
23
24
25 @Test
26 void returnIterator() throws IOException {
27 final String user = "testuser1";
28 MatcherAssert.assertThat(
29 "Value is null",
30 new MkRepoCommits(
31 new MkStorage.InFile(),
32 user,
33 new Coordinates.Simple(user, "testrepo1")
34 ).iterate(Collections.emptyMap()),
35 Matchers.notNullValue()
36 );
37 }
38
39
40
41
42
43 @Test
44 void getCommit() throws IOException {
45 final String user = "testuser2";
46 final String sha = "6dcb09b5b57875f334f61aebed695e2e4193db5e";
47 MatcherAssert.assertThat(
48 "Value is null",
49 new MkRepoCommits(
50 new MkStorage.InFile(),
51 user,
52 new Coordinates.Simple(user, "testrepo2")
53 ).get(sha),
54 Matchers.notNullValue()
55 );
56 }
57
58
59
60
61
62 @Test
63 void canCompare() throws IOException {
64 final String user = "testuser3";
65 MatcherAssert.assertThat(
66 "Value is null",
67 new MkRepoCommits(
68 new MkStorage.InFile(),
69 user,
70 new Coordinates.Simple(user, "testrepo3")
71 ).compare("5339b8e35b", "9b2e6efde9"),
72 Matchers.notNullValue()
73 );
74 }
75
76 @Test
77 void canCompareAsDiffFormat() throws IOException {
78 final String user = "testuser4";
79 final String base = "c034abc";
80 final String head = "a0ed832";
81 MatcherAssert.assertThat(
82 "Assertion failed",
83 new MkRepoCommits(
84 new MkStorage.InFile(),
85 user,
86 new Coordinates.Simple(user, "testrepo4")
87 ).diff(base, head),
88 Matchers.stringContainsInOrder(Arrays.asList(base, head))
89 );
90 }
91
92 @Test
93 void canCompareAsPatch() throws IOException {
94 final String user = "testuser5";
95 final String head = "9b2e6e7de9";
96 MatcherAssert.assertThat(
97 "Assertion failed",
98 new MkRepoCommits(
99 new MkStorage.InFile(), user,
100 new Coordinates.Simple(user, "testrepo5")
101 ).patch("5c39b8e35b", head),
102 Matchers.stringContainsInOrder(
103 Arrays.asList(
104 head, "From:", "Date:", "Subject:", "files changed",
105 "insertions", "deletions"
106 )
107 )
108 );
109 }
110 }