1
2
3
4
5 package com.jcabi.github;
6
7 import jakarta.json.Json;
8 import java.io.IOException;
9 import java.net.MalformedURLException;
10 import java.net.URI;
11 import java.net.URISyntaxException;
12 import org.hamcrest.MatcherAssert;
13 import org.hamcrest.Matchers;
14 import org.junit.jupiter.api.Test;
15 import org.mockito.Mockito;
16
17
18
19
20
21
22 final class RepoCommitTest {
23
24 @Test
25 void fetchesUrl() throws IOException, MalformedURLException, URISyntaxException {
26 final RepoCommit commit = Mockito.mock(RepoCommit.class);
27
28 final String prop = "https://api.github.com/repos/pengwynn/octokit/contents/README.md";
29 Mockito.doReturn(
30 Json.createObjectBuilder()
31 .add("url", prop)
32 .build()
33 ).when(commit).json();
34 MatcherAssert.assertThat(
35 "Values are not equal",
36 new RepoCommit.Smart(commit).url(),
37 Matchers.is(new URI(prop).toURL())
38 );
39 }
40
41 @Test
42 void fetchesMessage() throws IOException {
43 final RepoCommit commit = Mockito.mock(RepoCommit.class);
44 Mockito.doReturn(
45 Json.createObjectBuilder().add(
46 "commit",
47 Json.createObjectBuilder().add("message", "hello, world!")
48 ).build()
49 ).when(commit).json();
50 MatcherAssert.assertThat(
51 "String does not start with expected value",
52 new RepoCommit.Smart(commit).message(),
53 Matchers.startsWith("hello, ")
54 );
55 }
56
57
58
59
60
61 @Test
62 void verifiesStatus() throws IOException {
63 final RepoCommit commit = Mockito.mock(RepoCommit.class);
64 Mockito.doReturn(
65 Json.createObjectBuilder().add(
66 "commit",
67 Json.createObjectBuilder().add(
68 "verification",
69 Json.createObjectBuilder().add("verified", true)
70 ).build()
71 ).build()
72 ).when(commit).json();
73 MatcherAssert.assertThat(
74 "Values are not equal",
75 new RepoCommit.Smart(commit).isVerified(),
76 Matchers.is(true)
77 );
78 }
79
80
81
82
83
84 @Test
85 void readsAuthorLogin() throws IOException {
86 final RepoCommit commit = Mockito.mock(RepoCommit.class);
87 final String login = "jeff";
88 Mockito.doReturn(
89 Json.createObjectBuilder().add(
90 "commit",
91 Json.createObjectBuilder().add(
92 "author",
93 Json.createObjectBuilder().add("name", login)
94 ).build()
95 ).build()
96 ).when(commit).json();
97 MatcherAssert.assertThat(
98 "Values are not equal",
99 new RepoCommit.Smart(commit).author(),
100 Matchers.equalTo(login)
101 );
102 }
103 }