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.mock.MkGithub;
33 import com.jcabi.http.Request;
34 import com.jcabi.http.mock.MkAnswer;
35 import com.jcabi.http.mock.MkContainer;
36 import com.jcabi.http.mock.MkGrizzlyContainer;
37 import com.jcabi.http.mock.MkQuery;
38 import com.jcabi.http.request.ApacheRequest;
39 import com.jcabi.http.request.FakeRequest;
40 import java.net.HttpURLConnection;
41 import javax.json.Json;
42 import org.hamcrest.MatcherAssert;
43 import org.hamcrest.Matchers;
44 import org.junit.Rule;
45 import org.junit.Test;
46
47
48
49
50
51
52
53 public final class RtOrganizationTest {
54
55
56
57
58 @Rule
59 public final transient RandomPort resource = new RandomPort();
60
61
62
63
64
65
66 @Test
67 public void canFetchIssueAsJson() throws Exception {
68 final RtOrganization org = new RtOrganization(
69 new MkGithub(),
70 new FakeRequest().withBody("{\"organization\":\"json\"}"),
71 "testJson"
72 );
73 MatcherAssert.assertThat(
74 org.json().getString("organization"),
75 Matchers.equalTo("json")
76 );
77 }
78
79
80
81
82
83
84 @Test
85 public void patchWithJson() throws Exception {
86 try (
87 final MkContainer container = new MkGrizzlyContainer().next(
88 new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "response")
89 ).start(this.resource.port())
90 ) {
91 final RtOrganization org = new RtOrganization(
92 new MkGithub(),
93 new ApacheRequest(container.home()),
94 "testPatch"
95 );
96 org.patch(
97 Json.createObjectBuilder().add("patch", "test").build()
98 );
99 final MkQuery query = container.take();
100 MatcherAssert.assertThat(
101 query.method(),
102 Matchers.equalTo(Request.PATCH)
103 );
104 MatcherAssert.assertThat(
105 query.body(),
106 Matchers.equalTo("{\"patch\":\"test\"}")
107 );
108 container.stop();
109 }
110 }
111
112
113
114
115
116
117 @Test
118 public void canCompareInstances() throws Exception {
119 final RtOrganization less = new RtOrganization(
120 new MkGithub(),
121 new FakeRequest(),
122 "abc"
123 );
124 final RtOrganization greater = new RtOrganization(
125 new MkGithub(),
126 new FakeRequest(),
127 "def"
128 );
129 MatcherAssert.assertThat(
130 less.compareTo(greater), Matchers.lessThan(0)
131 );
132 MatcherAssert.assertThat(
133 greater.compareTo(less), Matchers.greaterThan(0)
134 );
135 MatcherAssert.assertThat(
136 less.compareTo(less), Matchers.equalTo(0)
137 );
138 }
139
140
141
142
143
144
145
146 @Test
147 public void canRepresentAsString() throws Exception {
148 try (
149 final MkContainer container = new MkGrizzlyContainer().next(
150 new MkAnswer.Simple(HttpURLConnection.HTTP_OK, "blah")
151 ).start(this.resource.port())
152 ) {
153 final RtOrganization org = new RtOrganization(
154 new MkGithub(),
155 new ApacheRequest(container.home()),
156 "testToString"
157 );
158 MatcherAssert.assertThat(
159 org.toString(),
160 Matchers.endsWith("/orgs/testToString")
161 );
162 container.stop();
163 }
164 }
165
166 }