1
2
3
4
5 package com.jcabi.github;
6
7 import jakarta.json.Json;
8 import jakarta.json.JsonObject;
9 import java.io.IOException;
10 import org.apache.commons.lang3.RandomStringUtils;
11 import org.hamcrest.MatcherAssert;
12 import org.hamcrest.Matchers;
13 import org.junit.jupiter.api.Test;
14 import org.mockito.Mockito;
15
16
17
18
19
20 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
21 final class PullCommentTest {
22
23
24
25
26 private static final String ID = "id";
27
28
29
30
31 private static final String COMMIT_ID = "commit_id";
32
33
34
35
36 private static final String URL = "url";
37
38
39
40
41 private static final String BODY = "body";
42
43 @Test
44 void fetchesId() throws IOException {
45 final PullComment comment = Mockito.mock(PullComment.class);
46 final String value = RandomStringUtils.secure().nextAlphanumeric(10);
47 Mockito.doReturn(
48 Json.createObjectBuilder().add(PullCommentTest.ID, value).build()
49 ).when(comment).json();
50 MatcherAssert.assertThat(
51 "Values are not equal",
52 new PullComment.Smart(comment).identifier(),
53 Matchers.is(value)
54 );
55 }
56
57 @Test
58 void updatesId() throws IOException {
59 final PullComment comment = Mockito.mock(PullComment.class);
60 final String value = RandomStringUtils.secure().nextAlphanumeric(10);
61 new PullComment.Smart(comment).identifier(value);
62 Mockito.verify(comment).patch(
63 Json.createObjectBuilder().add(PullCommentTest.ID, value).build()
64 );
65 }
66
67 @Test
68 void fetchesCommitId() throws IOException {
69 final PullComment comment = Mockito.mock(PullComment.class);
70 final String value = RandomStringUtils.secure().nextAlphanumeric(10);
71 Mockito.doReturn(
72 Json.createObjectBuilder().add(PullCommentTest.COMMIT_ID, value).build()
73 ).when(comment).json();
74 MatcherAssert.assertThat(
75 "Values are not equal",
76 new PullComment.Smart(comment).commitId(),
77 Matchers.is(value)
78 );
79 }
80
81 @Test
82 void updatesCommitId() throws IOException {
83 final PullComment comment = Mockito.mock(PullComment.class);
84 final String value = RandomStringUtils.secure().nextAlphanumeric(10);
85 new PullComment.Smart(comment).commitId(value);
86 Mockito.verify(comment).patch(
87 Json.createObjectBuilder().add(PullCommentTest.COMMIT_ID, value).build()
88 );
89 }
90
91 @Test
92 void fetchesUrl() throws IOException {
93 final PullComment comment = Mockito.mock(PullComment.class);
94 final String value = RandomStringUtils.secure().nextAlphanumeric(10);
95 Mockito.doReturn(
96 Json.createObjectBuilder().add(PullCommentTest.URL, value).build()
97 ).when(comment).json();
98 MatcherAssert.assertThat(
99 "Values are not equal",
100 new PullComment.Smart(comment).url(),
101 Matchers.is(value)
102 );
103 }
104
105 @Test
106 void updatesUrl() throws IOException {
107 final PullComment comment = Mockito.mock(PullComment.class);
108 final String value = RandomStringUtils.secure().nextAlphanumeric(10);
109 new PullComment.Smart(comment).url(value);
110 Mockito.verify(comment).patch(
111 Json.createObjectBuilder().add(PullCommentTest.URL, value).build()
112 );
113 }
114
115 @Test
116 void fetchesBody() throws IOException {
117 final PullComment comment = Mockito.mock(PullComment.class);
118 final String value = RandomStringUtils.secure().nextAlphanumeric(10);
119 Mockito.doReturn(
120 Json.createObjectBuilder().add(PullCommentTest.BODY, value).build()
121 ).when(comment).json();
122 MatcherAssert.assertThat(
123 "Values are not equal",
124 new PullComment.Smart(comment).body(),
125 Matchers.is(value)
126 );
127 }
128
129 @Test
130 void updatesBody() throws IOException {
131 final PullComment comment = Mockito.mock(PullComment.class);
132 final String value = RandomStringUtils.secure().nextAlphanumeric(10);
133 new PullComment.Smart(comment).body(value);
134 Mockito.verify(comment).patch(
135 Json.createObjectBuilder().add(PullCommentTest.BODY, value).build()
136 );
137 }
138
139 @Test
140 void retrievesAuthor() throws IOException {
141 final PullComment comment = Mockito.mock(PullComment.class);
142 final String value = RandomStringUtils.secure().nextAlphanumeric(10);
143 final JsonObject user = Json.createObjectBuilder()
144 .add("login", value).build();
145 Mockito.doReturn(
146 Json.createObjectBuilder().add("user", user).build()
147 ).when(comment).json();
148 MatcherAssert.assertThat(
149 "Values are not equal",
150 new PullComment.Smart(comment).author(),
151 Matchers.is(value)
152 );
153 }
154
155 }