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 java.io.IOException;
33 import java.net.URL;
34 import javax.json.Json;
35 import org.hamcrest.MatcherAssert;
36 import org.hamcrest.Matchers;
37 import org.junit.Test;
38 import org.mockito.Mockito;
39
40
41
42
43
44
45
46 public class RepoCommitTest {
47
48
49
50
51
52 @Test
53 public final void fetchesUrl() throws Exception {
54 final RepoCommit commit = Mockito.mock(RepoCommit.class);
55
56 final String prop = "https://api.github.com/repos/pengwynn/octokit/contents/README.md";
57 Mockito.doReturn(
58 Json.createObjectBuilder()
59 .add("url", prop)
60 .build()
61 ).when(commit).json();
62 MatcherAssert.assertThat(
63 new RepoCommit.Smart(commit).url(),
64 Matchers.is(new URL(prop))
65 );
66 }
67
68
69
70
71
72 @Test
73 public final void fetchesMessage() throws Exception {
74 final RepoCommit commit = Mockito.mock(RepoCommit.class);
75 Mockito.doReturn(
76 Json.createObjectBuilder().add(
77 "commit",
78 Json.createObjectBuilder().add("message", "hello, world!")
79 ).build()
80 ).when(commit).json();
81 MatcherAssert.assertThat(
82 new RepoCommit.Smart(commit).message(),
83 Matchers.startsWith("hello, ")
84 );
85 }
86
87
88
89
90
91 @Test
92 public final void verifiesStatus() throws IOException {
93 final RepoCommit commit = Mockito.mock(RepoCommit.class);
94 Mockito.doReturn(
95 Json.createObjectBuilder().add(
96 "commit",
97 Json.createObjectBuilder().add(
98 "verification",
99 Json.createObjectBuilder().add("verified", true)
100 ).build()
101 ).build()
102 ).when(commit).json();
103 MatcherAssert.assertThat(
104 new RepoCommit.Smart(commit).isVerified(),
105 Matchers.is(true)
106 );
107 }
108
109
110
111
112
113 @Test
114 public final void readsAuthorLogin() throws IOException {
115 final RepoCommit commit = Mockito.mock(RepoCommit.class);
116 final String login = "jeff";
117 Mockito.doReturn(
118 Json.createObjectBuilder().add(
119 "commit",
120 Json.createObjectBuilder().add(
121 "author",
122 Json.createObjectBuilder().add("name", login)
123 ).build()
124 ).build()
125 ).when(commit).json();
126 MatcherAssert.assertThat(
127 new RepoCommit.Smart(commit).author(),
128 Matchers.equalTo(login)
129 );
130 }
131 }