1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.jcabi.github.Reference;
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
20 final class MkReferenceTest {
21
22
23
24
25
26 @Test
27 void returnsName() throws Exception {
28 MatcherAssert.assertThat(
29 "Values are not equal",
30 MkReferenceTest.reference().ref(),
31 Matchers.is("refs/tags/hello")
32 );
33 }
34
35
36
37
38
39 @Test
40 void returnsRepo() throws Exception {
41 MatcherAssert.assertThat(
42 "Value is null",
43 MkReferenceTest.reference().repo(),
44 Matchers.notNullValue()
45 );
46 }
47
48
49
50
51
52 @Test
53 void fetchesJson() throws Exception {
54 final Reference ref = MkReferenceTest.reference();
55 final JsonObject json = ref.json();
56 MatcherAssert.assertThat(
57 "Values are not equal",
58 json.getString("ref"),
59 Matchers.is("refs/tags/hello")
60 );
61 MatcherAssert.assertThat(
62 "Values are not equal",
63 json.getString("sha"),
64 Matchers.is("testsha")
65 );
66 }
67
68
69
70
71
72 @Test
73 void patchesRef() throws Exception {
74 final Reference ref = MkReferenceTest.reference();
75 final JsonObject json = Json.createObjectBuilder()
76 .add("sha", "testshaPATCH")
77 .build();
78 ref.patch(json);
79 MatcherAssert.assertThat(
80 "Values are not equal",
81 ref.json().getString("sha"),
82 Matchers.is("testshaPATCH")
83 );
84 }
85
86
87
88
89
90 private static Reference reference() throws IOException {
91 return new MkGitHub().randomRepo().git()
92 .references().create("refs/tags/hello", "testsha");
93 }
94 }