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 final class RtPullRefTest {
20
21
22
23 private static final String SHA =
24 "7a1f68e743e8a81e158136c8661011fb55abd703";
25
26
27
28
29 private static final String REF = "some-branch";
30
31
32
33
34
35 @Test
36 void fetchesRepo() throws IOException {
37 final Repo repo = new MkGitHub().randomRepo();
38 MatcherAssert.assertThat(
39 "Values are not equal",
40 RtPullRefTest.pullRef(repo).repo().coordinates(),
41 Matchers.equalTo(repo.coordinates())
42 );
43 }
44
45
46
47
48
49 @Test
50 void fetchesRef() throws IOException {
51 MatcherAssert.assertThat(
52 "Values are not equal",
53 RtPullRefTest.pullRef().ref(),
54 Matchers.equalTo(RtPullRefTest.REF)
55 );
56 }
57
58
59
60
61
62 @Test
63 void fetchesSha() throws IOException {
64 MatcherAssert.assertThat(
65 "Values are not equal",
66 RtPullRefTest.pullRef().sha(),
67 Matchers.equalTo(RtPullRefTest.SHA)
68 );
69 }
70
71
72
73
74
75
76 private static PullRef pullRef() throws IOException {
77 return RtPullRefTest.pullRef(new MkGitHub().randomRepo());
78 }
79
80
81
82
83
84
85 private static PullRef pullRef(final Repo repo) {
86 final Coordinates coords = repo.coordinates();
87 final JsonObject user = Json.createObjectBuilder()
88 .add("login", coords.user())
89 .build();
90 return new RtPullRef(
91 repo.github(),
92 Json.createObjectBuilder()
93 .add("ref", RtPullRefTest.REF)
94 .add("sha", RtPullRefTest.SHA)
95 .add("user", user)
96 .add(
97 "repo",
98 Json.createObjectBuilder()
99 .add("owner", user)
100 .add("name", coords.repo())
101 .add("full_name", coords.toString())
102 .build()
103 ).build()
104 );
105 }
106 }