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.aspects.Tv;
33 import javax.json.Json;
34 import javax.json.JsonObject;
35 import org.apache.commons.lang3.RandomStringUtils;
36 import org.hamcrest.MatcherAssert;
37 import org.hamcrest.Matchers;
38 import org.junit.Test;
39 import org.mockito.Mockito;
40
41
42
43
44
45
46
47 public final class PullCommentTest {
48
49
50
51
52 private static final String ID = "id";
53
54
55
56
57 private static final String COMMIT_ID = "commit_id";
58
59
60
61
62 private static final String URL = "url";
63
64
65
66
67 private static final String BODY = "body";
68
69
70
71
72
73 @Test
74 public void fetchesId() throws Exception {
75 final PullComment comment = Mockito.mock(PullComment.class);
76 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
77 Mockito.doReturn(
78 Json.createObjectBuilder().add(ID, value).build()
79 ).when(comment).json();
80 MatcherAssert.assertThat(
81 new PullComment.Smart(comment).identifier(),
82 Matchers.is(value)
83 );
84 }
85
86
87
88
89
90 @Test
91 public void updatesId() throws Exception {
92 final PullComment comment = Mockito.mock(PullComment.class);
93 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
94 new PullComment.Smart(comment).identifier(value);
95 Mockito.verify(comment).patch(
96 Json.createObjectBuilder().add(ID, value).build()
97 );
98 }
99
100
101
102
103
104 @Test
105 public void fetchesCommitId() throws Exception {
106 final PullComment comment = Mockito.mock(PullComment.class);
107 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
108 Mockito.doReturn(
109 Json.createObjectBuilder().add(COMMIT_ID, value).build()
110 ).when(comment).json();
111 MatcherAssert.assertThat(
112 new PullComment.Smart(comment).commitId(),
113 Matchers.is(value)
114 );
115 }
116
117
118
119
120
121 @Test
122 public void updatesCommitId() throws Exception {
123 final PullComment comment = Mockito.mock(PullComment.class);
124 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
125 new PullComment.Smart(comment).commitId(value);
126 Mockito.verify(comment).patch(
127 Json.createObjectBuilder().add(COMMIT_ID, value).build()
128 );
129 }
130
131
132
133
134
135 @Test
136 public void fetchesUrl() throws Exception {
137 final PullComment comment = Mockito.mock(PullComment.class);
138 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
139 Mockito.doReturn(
140 Json.createObjectBuilder().add(URL, value).build()
141 ).when(comment).json();
142 MatcherAssert.assertThat(
143 new PullComment.Smart(comment).url(),
144 Matchers.is(value)
145 );
146 }
147
148
149
150
151
152 @Test
153 public void updatesUrl() throws Exception {
154 final PullComment comment = Mockito.mock(PullComment.class);
155 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
156 new PullComment.Smart(comment).url(value);
157 Mockito.verify(comment).patch(
158 Json.createObjectBuilder().add(URL, value).build()
159 );
160 }
161
162
163
164
165
166 @Test
167 public void fetchesBody() throws Exception {
168 final PullComment comment = Mockito.mock(PullComment.class);
169 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
170 Mockito.doReturn(
171 Json.createObjectBuilder().add(BODY, value).build()
172 ).when(comment).json();
173 MatcherAssert.assertThat(
174 new PullComment.Smart(comment).body(),
175 Matchers.is(value)
176 );
177 }
178
179
180
181
182
183 @Test
184 public void updatesBody() throws Exception {
185 final PullComment comment = Mockito.mock(PullComment.class);
186 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
187 new PullComment.Smart(comment).body(value);
188 Mockito.verify(comment).patch(
189 Json.createObjectBuilder().add(BODY, value).build()
190 );
191 }
192
193
194
195
196
197 @Test
198 public void retrievesAuthor() throws Exception {
199 final PullComment comment = Mockito.mock(PullComment.class);
200 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
201 final JsonObject user = Json.createObjectBuilder()
202 .add("login", value).build();
203 Mockito.doReturn(
204 Json.createObjectBuilder().add("user", user).build()
205 ).when(comment).json();
206 MatcherAssert.assertThat(
207 new PullComment.Smart(comment).author(),
208 Matchers.is(value)
209 );
210 }
211
212 }