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 com.jcabi.github.mock.MkGithub;
33 import java.io.IOException;
34 import javax.json.Json;
35 import javax.json.JsonObject;
36 import org.hamcrest.MatcherAssert;
37 import org.hamcrest.Matchers;
38 import org.junit.Test;
39
40
41
42
43
44
45
46
47 public final class PullRefTest {
48
49
50
51 private static final String REF = "the-ref";
52
53
54
55
56 private static final String SHA = "7a1f68e743e8a81e158136c8661011fb55abd703";
57
58
59
60 private static final String LABEL = "pr-ref-label";
61
62
63
64
65
66 @Test
67 public void fetchesRepo() throws IOException {
68 final Repo repo = new MkGithub().randomRepo();
69 MatcherAssert.assertThat(
70 PullRefTest.pullRef(repo).repo().coordinates(),
71 Matchers.equalTo(repo.coordinates())
72 );
73 }
74
75
76
77
78
79 @Test
80 public void fetchesRef() throws IOException {
81 MatcherAssert.assertThat(
82 PullRefTest.pullRef().ref(),
83 Matchers.equalTo(PullRefTest.REF)
84 );
85 }
86
87
88
89
90
91 @Test
92 public void fetchesSha() throws IOException {
93 MatcherAssert.assertThat(
94 PullRefTest.pullRef().sha(),
95 Matchers.equalTo(PullRefTest.SHA)
96 );
97 }
98
99
100
101
102
103 @Test
104 public void fetchesLabel() throws IOException {
105 MatcherAssert.assertThat(
106 PullRefTest.pullRef().label(),
107 Matchers.equalTo(PullRefTest.LABEL)
108 );
109 }
110
111
112
113
114
115 @Test
116 public void fetchesCommit() throws IOException {
117 final Repo repo = new MkGithub().randomRepo();
118 final Commit commit = PullRefTest.pullRef(repo).commit();
119 MatcherAssert.assertThat(
120 commit.repo().coordinates(),
121 Matchers.equalTo(repo.coordinates())
122 );
123 MatcherAssert.assertThat(
124 commit.sha(),
125 Matchers.equalTo(PullRefTest.SHA)
126 );
127 }
128
129
130
131
132
133 @Test
134 public void fetchesUser() throws IOException {
135 final Repo repo = new MkGithub().randomRepo();
136 MatcherAssert.assertThat(
137 PullRefTest.pullRef(repo).user().login(),
138 Matchers.equalTo(repo.coordinates().user())
139 );
140 }
141
142
143
144
145
146
147 private static PullRef.Smart pullRef(final Repo repo) {
148 final Coordinates coords = repo.coordinates();
149 final JsonObject user = Json.createObjectBuilder()
150 .add("login", coords.user())
151 .build();
152 return new PullRef.Smart(
153 new RtPullRef(
154 repo.github(),
155 Json.createObjectBuilder()
156 .add("label", PullRefTest.LABEL)
157 .add("ref", PullRefTest.REF)
158 .add("sha", PullRefTest.SHA)
159 .add("user", user)
160 .add(
161 "repo",
162 Json.createObjectBuilder()
163 .add("name", coords.repo())
164 .add("full_name", coords.toString())
165 .add("owner", user)
166 .build()
167 ).build()
168 )
169 );
170 }
171
172
173
174
175
176
177 private static PullRef.Smart pullRef() throws IOException {
178 return PullRefTest.pullRef(new MkGithub().randomRepo());
179 }
180 }