1
2
3
4
5 package com.jcabi.github;
6
7 import java.io.IOException;
8 import java.util.Collections;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.junit.jupiter.api.Test;
12
13
14
15
16
17 @OAuthScope(OAuthScope.Scope.GIST)
18 final class RtGistsITCase {
19 @Test
20 void createGist() throws IOException {
21 final String filename = "filename.txt";
22 final String content = "content of file";
23 final Gists gists = RtGistsITCase.gists();
24 final Gist gist = gists.create(
25 Collections.singletonMap(filename, content), false
26 );
27 final Gist.Smart smart = new Gist.Smart(gist);
28 MatcherAssert.assertThat(
29 "Values are not equal",
30 smart.read(filename),
31 Matchers.equalTo(content)
32 );
33 gists.remove(smart.identifier());
34 }
35
36 @Test
37 void iterateGists() throws IOException {
38 final Gists gists = RtGistsITCase.gists();
39 final Gist gist = gists.create(
40 Collections.singletonMap("test.txt", "content"), false
41 );
42 MatcherAssert.assertThat(
43 "Collection does not contain expected item",
44 gists.iterate(),
45 Matchers.hasItem(gist)
46 );
47 gists.remove(gist.identifier());
48 }
49
50 @Test
51 void singleGist() throws IOException {
52 final String filename = "single-name.txt";
53 final Gists gists = RtGistsITCase.gists();
54 final Gist gist = gists.create(
55 Collections.singletonMap(filename, "body"), false
56 );
57 MatcherAssert.assertThat(
58 "Values are not equal",
59 gists.get(gist.identifier()).identifier(),
60 Matchers.equalTo(gist.identifier())
61 );
62 gists.remove(gist.identifier());
63 }
64
65 @Test
66 void removesGistByName() throws IOException {
67 final Gists gists = RtGistsITCase.gists();
68 final Gist gist = gists.create(
69 Collections.singletonMap("fileName.txt", "content of test file"),
70 false
71 );
72 MatcherAssert.assertThat(
73 "Value is null",
74 gists.iterate(),
75 Matchers.notNullValue()
76 );
77 gists.remove(gist.json().getString("id"));
78 MatcherAssert.assertThat(
79 "Collection does not contain expected item",
80 gists.iterate(),
81 Matchers.not(Matchers.hasItem(gist))
82 );
83 }
84
85
86
87
88
89 private static Gists gists() {
90 return GitHubIT.connect().gists();
91 }
92 }