View Javadoc
1   /**
2    * Copyright (c) 2013-2022, jcabi.com
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met: 1) Redistributions of source code must retain the above
8    * copyright notice, this list of conditions and the following
9    * disclaimer. 2) Redistributions in binary form must reproduce the above
10   * copyright notice, this list of conditions and the following
11   * disclaimer in the documentation and/or other materials provided
12   * with the distribution. 3) Neither the name of the jcabi.com nor
13   * the names of its contributors may be used to endorse or promote
14   * products derived from this software without specific prior written
15   * permission.
16   *
17   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21   * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28   * OF THE POSSIBILITY OF SUCH DAMAGE.
29   */
30  package com.jcabi.github;
31  
32  import javax.json.Json;
33  import org.hamcrest.MatcherAssert;
34  import org.hamcrest.Matchers;
35  import org.junit.Test;
36  import org.mockito.Mockito;
37  
38  /**
39   * Tests for {@link Organization}.
40   * @author Paul Polishchuk (ppol@ua.fm)
41   * @version $Id: 0e1b5df7561f80b7260bbbcdac84488be011891c $
42   */
43  @SuppressWarnings("PMD.TooManyMethods")
44  public final class OrganizationTest {
45  
46      /**
47       * Organization.Smart can fetch url from an Organization.
48       * @throws Exception If some problem inside
49       */
50      @Test
51      public void fetchesUrl() throws Exception {
52          final Organization orgn = Mockito.mock(Organization.class);
53          Mockito.doReturn(
54              Json.createObjectBuilder()
55                  .add("url", "https://api.github.com/orgs/github")
56                  .build()
57          ).when(orgn).json();
58          MatcherAssert.assertThat(
59              new Organization.Smart(orgn).url(),
60              Matchers.notNullValue()
61          );
62      }
63  
64      /**
65       * Organization.Smart can fetch avatar_url from an Organization.
66       * @throws Exception If some problem inside
67       */
68      @Test
69      public void fetchesAvatarUrl() throws Exception {
70          final Organization orgn = Mockito.mock(Organization.class);
71          Mockito.doReturn(
72              Json.createObjectBuilder()
73                  .add("avatar_url", "https://github.com/images/happy.gif")
74                  .build()
75          ).when(orgn).json();
76          MatcherAssert.assertThat(
77              new Organization.Smart(orgn).avatarUrl(),
78              Matchers.notNullValue()
79          );
80      }
81  
82      /**
83       * Organization.Smart can fetch name from an Organization.
84       * @throws Exception If some problem inside
85       */
86      @Test
87      public void fetchesName() throws Exception {
88          final Organization orgn = Mockito.mock(Organization.class);
89          Mockito.doReturn(
90              Json.createObjectBuilder()
91                  .add("name", "github")
92                  .build()
93          ).when(orgn).json();
94          MatcherAssert.assertThat(
95              new Organization.Smart(orgn).name(),
96              Matchers.notNullValue()
97          );
98      }
99  
100     /**
101      * Organization.Smart can fetch company from an Organization.
102      * @throws Exception If some problem inside
103      */
104     @Test
105     public void fetchesCompany() throws Exception {
106         final Organization orgn = Mockito.mock(Organization.class);
107         Mockito.doReturn(
108             Json.createObjectBuilder()
109                 .add("company", "GitHub")
110                 .build()
111         ).when(orgn).json();
112         MatcherAssert.assertThat(
113             new Organization.Smart(orgn).company(),
114             Matchers.notNullValue()
115         );
116     }
117 
118     /**
119      * Organization.Smart can fetch blog from an Organization.
120      * @throws Exception If some problem inside
121      */
122     @Test
123     public void fetchesBlog() throws Exception {
124         final Organization orgn = Mockito.mock(Organization.class);
125         Mockito.doReturn(
126             Json.createObjectBuilder()
127                 .add("blog", "https://github.com/blog")
128                 .build()
129         ).when(orgn).json();
130         MatcherAssert.assertThat(
131             new Organization.Smart(orgn).blog(),
132             Matchers.notNullValue()
133         );
134     }
135 
136     /**
137      * Organization.Smart can fetch location from an Organization.
138      * @throws Exception If some problem inside
139      */
140     @Test
141     public void fetchesLocation() throws Exception {
142         final Organization orgn = Mockito.mock(Organization.class);
143         Mockito.doReturn(
144             Json.createObjectBuilder()
145                 .add("location", "https://github.com/location")
146                 .build()
147         ).when(orgn).json();
148         MatcherAssert.assertThat(
149             new Organization.Smart(orgn).location(),
150             Matchers.notNullValue()
151         );
152     }
153 
154     /**
155      * Organization.Smart can fetch email from an Organization.
156      * @throws Exception If some problem inside
157      */
158     @Test
159     public void fetchesEmail() throws Exception {
160         final Organization orgn = Mockito.mock(Organization.class);
161         Mockito.doReturn(
162             Json.createObjectBuilder()
163                 .add("email", "octocat@github.com")
164                 .build()
165         ).when(orgn).json();
166         MatcherAssert.assertThat(
167             new Organization.Smart(orgn).email(),
168             Matchers.notNullValue()
169         );
170     }
171 
172     /**
173      * Organization.Smart can fetch billing_email from an Organization.
174      * @throws Exception If some problem inside
175      */
176     @Test
177     public void fetchesBillingEmail() throws Exception {
178         final Organization orgn = Mockito.mock(Organization.class);
179         Mockito.doReturn(
180             Json.createObjectBuilder()
181                 .add("billing_email", "octocat_billing@github.com")
182                 .build()
183         ).when(orgn).json();
184         MatcherAssert.assertThat(
185             new Organization.Smart(orgn).billingEmail(),
186             Matchers.notNullValue()
187         );
188     }
189 
190     /**
191      * Organization.Smart can fetch public_repos from an Organization.
192      * @throws Exception If some problem inside
193      */
194     @Test
195     public void fetchesPublicRepos() throws Exception {
196         final Organization orgn = Mockito.mock(Organization.class);
197         Mockito.doReturn(
198             Json.createObjectBuilder()
199                 .add("public_repos", 1)
200                 .build()
201         ).when(orgn).json();
202         MatcherAssert.assertThat(
203             new Organization.Smart(orgn).publicRepos(),
204             Matchers.notNullValue()
205         );
206     }
207 
208     /**
209      * Organization.Smart can fetch public_gists from an Organization.
210      * @throws Exception If some problem inside
211      */
212     @Test
213     public void fetchesPublicGists() throws Exception {
214         final Organization orgn = Mockito.mock(Organization.class);
215         Mockito.doReturn(
216             Json.createObjectBuilder()
217                 .add("public_gists", 1)
218                 .build()
219         ).when(orgn).json();
220         MatcherAssert.assertThat(
221             new Organization.Smart(orgn).publicGists(),
222             Matchers.notNullValue()
223         );
224     }
225 
226     /**
227      * Organization.Smart can fetch followers from an Organization.
228      * @throws Exception If some problem inside
229      */
230     @Test
231     public void fetchesFollowers() throws Exception {
232         final Organization orgn = Mockito.mock(Organization.class);
233         Mockito.doReturn(
234             Json.createObjectBuilder()
235                 .add("followers", 1)
236                 .build()
237         ).when(orgn).json();
238         MatcherAssert.assertThat(
239             new Organization.Smart(orgn).followers(),
240             Matchers.notNullValue()
241         );
242     }
243 
244     /**
245      * Organization.Smart can fetch following from an Organization.
246      * @throws Exception If some problem inside
247      */
248     @Test
249     public void fetchesFollowing() throws Exception {
250         final Organization orgn = Mockito.mock(Organization.class);
251         Mockito.doReturn(
252             Json.createObjectBuilder()
253                 .add("following", 1)
254                 .build()
255         ).when(orgn).json();
256         MatcherAssert.assertThat(
257             new Organization.Smart(orgn).following(),
258             Matchers.notNullValue()
259         );
260     }
261 
262     /**
263      * Organization.Smart can fetch html_url from an Organization.
264      * @throws Exception If some problem inside
265      */
266     @Test
267     public void fetchesHtmlUrl() throws Exception {
268         final Organization orgn = Mockito.mock(Organization.class);
269         Mockito.doReturn(
270             Json.createObjectBuilder()
271                 .add("html_url", "https://github.com/octocat")
272                 .build()
273         ).when(orgn).json();
274         MatcherAssert.assertThat(
275             new Organization.Smart(orgn).htmlUrl(),
276             Matchers.notNullValue()
277         );
278     }
279 
280     /**
281      * Organization.Smart can fetch created_at from an Organization.
282      * @throws Exception If some problem inside
283      */
284     @Test
285     public void fetchesCreatedAt() throws Exception {
286         final Organization orgn = Mockito.mock(Organization.class);
287         Mockito.doReturn(
288             Json.createObjectBuilder()
289                 .add("created_at", "2008-01-14T04:33:35Z")
290                 .build()
291         ).when(orgn).json();
292         MatcherAssert.assertThat(
293             new Organization.Smart(orgn).createdAt(),
294             Matchers.notNullValue()
295         );
296     }
297 
298     /**
299      * Organization.Smart can fetch type from an Organization.
300      * @throws Exception If some problem inside
301      */
302     @Test
303     public void fetchesType() throws Exception {
304         final Organization orgn = Mockito.mock(Organization.class);
305         Mockito.doReturn(
306             Json.createObjectBuilder()
307                 .add("type", "Organization")
308                 .build()
309         ).when(orgn).json();
310         MatcherAssert.assertThat(
311             new Organization.Smart(orgn).type(),
312             Matchers.notNullValue()
313         );
314     }
315 }