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.Assume;
37 import org.junit.Test;
38
39
40
41
42
43
44 @OAuthScope(Scope.GIST)
45 public final class RtGistITCase {
46
47
48
49
50
51 @Test
52 public void readsAndWritesGists() throws Exception {
53 final String filename = "filename.txt";
54 final String content = "content of file";
55 final Gists gists = RtGistITCase.github().gists();
56 Gist.Smart smart = null;
57 try {
58 final Gist gist = gists.create(
59 Collections.singletonMap(filename, content), false
60 );
61 smart = new Gist.Smart(gist);
62 final String file = smart.files().iterator().next();
63 gist.write(file, "hey, works for you this way?");
64 MatcherAssert.assertThat(
65 gist.read(file),
66 Matchers.startsWith("hey, works for ")
67 );
68 } finally {
69 if (smart != null) {
70 gists.remove(smart.identifier());
71 }
72 }
73 }
74
75
76
77
78
79
80
81 @Test
82 public void forksGist() throws Exception {
83 final String filename = "filename1.txt";
84 final String content = "content of file1";
85 final Gists gists1 = RtGistITCase.github("failsafe.github.key").gists();
86 final Gists gists2 = RtGistITCase.github("failsafe.github.key.second")
87 .gists();
88 final Gist gist = gists1.get(
89 gists2.create(Collections.singletonMap(filename, content), false)
90 .identifier()
91 );
92 final Gist forked = gist.fork();
93 try {
94 MatcherAssert.assertThat(
95 forked.read(filename),
96 Matchers.equalTo(content)
97 );
98 } finally {
99 gists1.remove(forked.identifier());
100 gists2.remove(gist.identifier());
101 }
102 }
103
104
105
106
107
108
109 private static Github github() {
110 return RtGistITCase.github("failsafe.github.key");
111 }
112
113
114
115
116
117
118 private static Github github(final String property) {
119 final String key = System.getProperty(property);
120 Assume.assumeThat(
121 key,
122 Matchers.not(Matchers.is(Matchers.emptyOrNullString()))
123 );
124 return new RtGithub(key);
125 }
126
127 }