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.github.Gist;
33 import com.jcabi.github.Gists;
34 import java.io.IOException;
35 import java.util.Collections;
36 import org.hamcrest.MatcherAssert;
37 import org.hamcrest.Matchers;
38 import org.junit.Test;
39
40
41
42
43
44
45
46 public final class MkGistsTest {
47
48
49
50
51
52 @Test
53 public void worksWithMockedGists() throws Exception {
54 final Gist gist = new MkGithub().gists().create(
55 Collections.singletonMap("test-file-name.txt", "none"), false
56 );
57 final String file = "t.txt";
58 gist.write(file, "hello, everybody!");
59 MatcherAssert.assertThat(
60 gist.read(file),
61 Matchers.startsWith("hello, ")
62 );
63 }
64
65
66
67
68
69 @Test
70 public void removesGistByIdentifier() throws Exception {
71 final Gists gists = new MkGithub().gists();
72 final Gist gist = gists.create(
73 Collections.singletonMap("fileName.txt", "content"), false
74 );
75 MatcherAssert.assertThat(
76 gists.iterate(),
77 Matchers.hasItem(gist)
78 );
79 gists.remove(gist.identifier());
80 MatcherAssert.assertThat(
81 gists.iterate(),
82 Matchers.not(Matchers.hasItem(gist))
83 );
84 }
85
86
87
88
89
90 @Test
91 public void worksWithSeveralGists() throws Exception {
92 final Gists gists = new MkGithub().gists();
93 final Gist gist = gists.create(
94 Collections.singletonMap("test-file-name.txt", "none"), false
95 );
96 final Gist othergist = gists.create(
97 Collections.singletonMap("test-file-name2.txt", ""), false
98 );
99 final String file = "t.txt";
100 gist.write(file, "hello, everybody!");
101 othergist.write(file, "bye, everybody!");
102 MatcherAssert.assertThat(
103 gist.read(file),
104 Matchers.startsWith("hello, ")
105 );
106 MatcherAssert.assertThat(
107 othergist.read(file),
108 Matchers.startsWith("bye, ")
109 );
110 }
111
112
113
114
115
116 @Test
117 public void testStar() throws Exception {
118 final Gist gist = new MkGithub().gists().create(
119 Collections.singletonMap("file-name.txt", ""), false
120 );
121 MatcherAssert.assertThat(
122 gist.starred(),
123 Matchers.equalTo(false)
124 );
125 gist.star();
126 MatcherAssert.assertThat(
127 gist.starred(),
128 Matchers.equalTo(true)
129 );
130 }
131
132
133
134
135
136 @Test
137 public void testUnstar() throws Exception {
138 final Gist gist = new MkGithub().gists().create(
139 Collections.singletonMap("file-name.txt", ""), false
140 );
141 MatcherAssert.assertThat(
142 gist.starred(),
143 Matchers.equalTo(false)
144 );
145 gist.star();
146 MatcherAssert.assertThat(
147 gist.starred(),
148 Matchers.equalTo(true)
149 );
150 gist.unstar();
151 MatcherAssert.assertThat(
152 gist.starred(),
153 Matchers.equalTo(false)
154 );
155 }
156
157
158
159
160
161 @Test
162 public void createGistWithEmptyFile() throws IOException {
163 final String filename = "file.txt";
164 final Gist gist = new MkGithub().gists().create(
165 Collections.singletonMap(filename, ""), false
166 );
167 MatcherAssert.assertThat(
168 gist.read(filename),
169 Matchers.is(Matchers.emptyString())
170 );
171 }
172
173 }