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.mock;
31
32 import com.jcabi.aspects.Tv;
33 import com.jcabi.github.Comment;
34 import com.jcabi.github.Coordinates;
35 import com.jcabi.github.Repos;
36 import java.net.URL;
37 import java.util.Date;
38 import org.hamcrest.MatcherAssert;
39 import org.hamcrest.Matchers;
40 import org.junit.Test;
41 import org.mockito.Mockito;
42
43
44
45
46
47
48 public final class MkCommentTest {
49
50
51
52
53 @Test
54 public void changesBody() throws Exception {
55 final Comment comment = this.comment("hey buddy");
56 new Comment.Smart(comment).body("hello, this is a new body");
57 MatcherAssert.assertThat(
58 new Comment.Smart(comment).body(),
59 Matchers.startsWith("hello, this ")
60 );
61 }
62
63
64
65
66
67
68 @Test
69 public void canCompareInstances() throws Exception {
70 final MkComment less = new MkComment(
71 new MkStorage.InFile(),
72 "login-less",
73 Mockito.mock(Coordinates.class),
74 1,
75 1
76 );
77 final MkComment greater = new MkComment(
78 new MkStorage.InFile(),
79 "login-greater",
80 Mockito.mock(Coordinates.class),
81 2,
82 2
83 );
84 MatcherAssert.assertThat(
85 less.compareTo(greater),
86 Matchers.lessThan(0)
87 );
88 MatcherAssert.assertThat(
89 greater.compareTo(less),
90 Matchers.greaterThan(0)
91 );
92 }
93
94
95
96
97
98
99 @Test
100 public void dataStoredProperly() throws Exception {
101 final String cmt = "what's up?";
102 final long before = MkCommentTest.now();
103 final Comment comment = this.comment(cmt);
104 final long after = MkCommentTest.now();
105 MatcherAssert.assertThat(
106 comment.number(),
107 Matchers.greaterThan(0)
108 );
109 final Comment.Smart smart = new Comment.Smart(comment);
110 MatcherAssert.assertThat(
111 smart.issue().number(),
112 Matchers.greaterThan(0)
113 );
114 MatcherAssert.assertThat(
115 smart.author().login(),
116 Matchers.equalTo("jeff")
117 );
118 MatcherAssert.assertThat(
119 smart.body(),
120 Matchers.equalTo(cmt)
121 );
122 MatcherAssert.assertThat(
123 smart.url(),
124 Matchers.equalTo(
125 new URL(
126
127 "https://api.jcabi-github.invalid/repos/jeff/blueharvest/issues/comments/1"
128 )
129 )
130 );
131 MatcherAssert.assertThat(
132 smart.createdAt().getTime(),
133 Matchers.greaterThanOrEqualTo(before)
134 );
135 MatcherAssert.assertThat(
136 smart.createdAt().getTime(),
137 Matchers.lessThanOrEqualTo(after)
138 );
139 MatcherAssert.assertThat(
140 smart.updatedAt().getTime(),
141 Matchers.greaterThanOrEqualTo(before)
142 );
143 MatcherAssert.assertThat(
144 smart.updatedAt().getTime(),
145 Matchers.lessThanOrEqualTo(after)
146 );
147 }
148
149
150
151
152
153
154
155 private Comment comment(final String text) throws Exception {
156 return new MkGithub().repos().create(
157 new Repos.RepoCreate("blueharvest", false)
158 ).issues().create("hey", "how are you?").comments().post(text);
159 }
160
161
162
163
164
165 private static long now() {
166 final long sinceepoch = new Date().getTime();
167 return sinceepoch - sinceepoch % Tv.THOUSAND;
168 }
169 }