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.github.OAuthScope.Scope;
33 import java.util.Collections;
34 import org.hamcrest.MatcherAssert;
35 import org.hamcrest.Matchers;
36 import org.junit.Test;
37
38
39
40
41
42
43 @OAuthScope(Scope.GIST)
44 public final class RtGistsITCase {
45
46
47
48
49 @Test
50 public void createGist() throws Exception {
51 final String filename = "filename.txt";
52 final String content = "content of file";
53 final Gists gists = RtGistsITCase.gists();
54 final Gist gist = gists.create(
55 Collections.singletonMap(filename, content), false
56 );
57 final Gist.Smart smart = new Gist.Smart(gist);
58 MatcherAssert.assertThat(
59 smart.read(filename),
60 Matchers.equalTo(content)
61 );
62 gists.remove(smart.identifier());
63 }
64
65
66
67
68
69 @Test
70 public void iterateGists() throws Exception {
71 final Gists gists = RtGistsITCase.gists();
72 final Gist gist = gists.create(
73 Collections.singletonMap("test.txt", "content"), false
74 );
75 MatcherAssert.assertThat(
76 gists.iterate(),
77 Matchers.hasItem(gist)
78 );
79 gists.remove(gist.identifier());
80 }
81
82
83
84
85 @Test
86 public void singleGist() throws Exception {
87 final String filename = "single-name.txt";
88 final Gists gists = RtGistsITCase.gists();
89 final Gist gist = gists.create(
90 Collections.singletonMap(filename, "body"), false
91 );
92 MatcherAssert.assertThat(
93 gists.get(gist.identifier()).identifier(),
94 Matchers.equalTo(gist.identifier())
95 );
96 gists.remove(gist.identifier());
97 }
98
99
100
101
102 @Test
103 public void removesGistByName() throws Exception {
104 final Gists gists = RtGistsITCase.gists();
105 final Gist gist = gists.create(
106 Collections.singletonMap("fileName.txt", "content of test file"),
107 false
108 );
109 MatcherAssert.assertThat(
110 gists.iterate(),
111 Matchers.notNullValue()
112 );
113 gists.remove(gist.json().getString("id"));
114 MatcherAssert.assertThat(
115 gists.iterate(),
116 Matchers.not(Matchers.hasItem(gist))
117 );
118 }
119
120
121
122
123 private static Gists gists() {
124 return new GithubIT().connect().gists();
125 }
126 }