1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.github.mock.MkGitHub;
8 import jakarta.json.Json;
9 import jakarta.json.JsonObject;
10 import java.io.IOException;
11 import org.hamcrest.MatcherAssert;
12 import org.hamcrest.Matchers;
13 import org.junit.jupiter.api.Test;
14
15
16
17
18
19 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
20 final class PullRefTest {
21
22
23
24 private static final String REF = "the-ref";
25
26
27
28
29
30 private static final String SHA = "7a1f68e743e8a81e158136c8661011fb55abd703";
31
32
33
34
35 private static final String LABEL = "pr-ref-label";
36
37
38
39
40
41 @Test
42 void fetchesRepo() throws IOException {
43 final Repo repo = new MkGitHub().randomRepo();
44 MatcherAssert.assertThat(
45 "Values are not equal",
46 PullRefTest.pullRef(repo).repo().coordinates(),
47 Matchers.equalTo(repo.coordinates())
48 );
49 }
50
51
52
53
54
55 @Test
56 void fetchesRef() throws IOException {
57 MatcherAssert.assertThat(
58 "Values are not equal",
59 PullRefTest.pullRef().ref(),
60 Matchers.equalTo(PullRefTest.REF)
61 );
62 }
63
64
65
66
67
68 @Test
69 void fetchesSha() throws IOException {
70 MatcherAssert.assertThat(
71 "Values are not equal",
72 PullRefTest.pullRef().sha(),
73 Matchers.equalTo(PullRefTest.SHA)
74 );
75 }
76
77
78
79
80
81 @Test
82 void fetchesLabel() throws IOException {
83 MatcherAssert.assertThat(
84 "Values are not equal",
85 PullRefTest.pullRef().label(),
86 Matchers.equalTo(PullRefTest.LABEL)
87 );
88 }
89
90
91
92
93
94 @Test
95 void fetchesCommit() throws IOException {
96 final Repo repo = new MkGitHub().randomRepo();
97 final Commit commit = PullRefTest.pullRef(repo).commit();
98 MatcherAssert.assertThat(
99 "Values are not equal",
100 commit.repo().coordinates(),
101 Matchers.equalTo(repo.coordinates())
102 );
103 MatcherAssert.assertThat(
104 "Values are not equal",
105 commit.sha(),
106 Matchers.equalTo(PullRefTest.SHA)
107 );
108 }
109
110
111
112
113
114 @Test
115 void fetchesUser() throws IOException {
116 final Repo repo = new MkGitHub().randomRepo();
117 MatcherAssert.assertThat(
118 "Values are not equal",
119 PullRefTest.pullRef(repo).user().login(),
120 Matchers.equalTo(repo.coordinates().user())
121 );
122 }
123
124
125
126
127
128
129 private static PullRef.Smart pullRef(final Repo repo) {
130 final Coordinates coords = repo.coordinates();
131 final JsonObject user = Json.createObjectBuilder()
132 .add("login", coords.user())
133 .build();
134 return new PullRef.Smart(
135 new RtPullRef(
136 repo.github(),
137 Json.createObjectBuilder()
138 .add("label", PullRefTest.LABEL)
139 .add("ref", PullRefTest.REF)
140 .add("sha", PullRefTest.SHA)
141 .add("user", user)
142 .add(
143 "repo",
144 Json.createObjectBuilder()
145 .add("name", coords.repo())
146 .add("full_name", coords.toString())
147 .add("owner", user)
148 .build()
149 ).build()
150 )
151 );
152 }
153
154
155
156
157
158
159 private static PullRef.Smart pullRef() throws IOException {
160 return PullRefTest.pullRef(new MkGitHub().randomRepo());
161 }
162 }