View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github;
6   
7   import jakarta.json.Json;
8   import java.io.IOException;
9   import org.hamcrest.MatcherAssert;
10  import org.hamcrest.Matchers;
11  import org.junit.jupiter.api.Test;
12  import org.mockito.Mockito;
13  
14  /**
15   * Tests for {@link Organization}.
16   * @since 0.1
17   */
18  @SuppressWarnings({"PMD.TooManyMethods", "PMD.AvoidDuplicateLiterals"})
19  final class OrganizationTest {
20  
21      @Test
22      void fetchesUrl() throws IOException {
23          final Organization orgn = Mockito.mock(Organization.class);
24          Mockito.doReturn(
25              Json.createObjectBuilder()
26                  .add("url", "https://api.github.com/orgs/github")
27                  .build()
28          ).when(orgn).json();
29          MatcherAssert.assertThat(
30              "Value is null",
31              new Organization.Smart(orgn).url(),
32              Matchers.notNullValue()
33          );
34      }
35  
36      @Test
37      void fetchesAvatarUrl() throws IOException {
38          final Organization orgn = Mockito.mock(Organization.class);
39          Mockito.doReturn(
40              Json.createObjectBuilder()
41                  .add("avatar_url", "https://github.com/images/happy.gif")
42                  .build()
43          ).when(orgn).json();
44          MatcherAssert.assertThat(
45              "Value is null",
46              new Organization.Smart(orgn).avatarUrl(),
47              Matchers.notNullValue()
48          );
49      }
50  
51      @Test
52      void fetchesName() throws IOException {
53          final Organization orgn = Mockito.mock(Organization.class);
54          Mockito.doReturn(
55              Json.createObjectBuilder()
56                  .add("name", "github")
57                  .build()
58          ).when(orgn).json();
59          MatcherAssert.assertThat(
60              "Value is null",
61              new Organization.Smart(orgn).name(),
62              Matchers.notNullValue()
63          );
64      }
65  
66      @Test
67      void fetchesCompany() throws IOException {
68          final Organization orgn = Mockito.mock(Organization.class);
69          Mockito.doReturn(
70              Json.createObjectBuilder()
71                  .add("company", "GitHub")
72                  .build()
73          ).when(orgn).json();
74          MatcherAssert.assertThat(
75              "Value is null",
76              new Organization.Smart(orgn).company(),
77              Matchers.notNullValue()
78          );
79      }
80  
81      @Test
82      void fetchesBlog() throws IOException {
83          final Organization orgn = Mockito.mock(Organization.class);
84          Mockito.doReturn(
85              Json.createObjectBuilder()
86                  .add("blog", "https://github.com/blog")
87                  .build()
88          ).when(orgn).json();
89          MatcherAssert.assertThat(
90              "Value is null",
91              new Organization.Smart(orgn).blog(),
92              Matchers.notNullValue()
93          );
94      }
95  
96      @Test
97      void fetchesLocation() throws IOException {
98          final Organization orgn = Mockito.mock(Organization.class);
99          Mockito.doReturn(
100             Json.createObjectBuilder()
101                 .add("location", "https://github.com/location")
102                 .build()
103         ).when(orgn).json();
104         MatcherAssert.assertThat(
105             "Value is null",
106             new Organization.Smart(orgn).location(),
107             Matchers.notNullValue()
108         );
109     }
110 
111     @Test
112     void fetchesEmail() throws IOException {
113         final Organization orgn = Mockito.mock(Organization.class);
114         Mockito.doReturn(
115             Json.createObjectBuilder()
116                 .add("email", "octocat@github.com")
117                 .build()
118         ).when(orgn).json();
119         MatcherAssert.assertThat(
120             "Value is null",
121             new Organization.Smart(orgn).email(),
122             Matchers.notNullValue()
123         );
124     }
125 
126     @Test
127     void fetchesBillingEmail() throws IOException {
128         final Organization orgn = Mockito.mock(Organization.class);
129         Mockito.doReturn(
130             Json.createObjectBuilder()
131                 .add("billing_email", "octocat_billing@github.com")
132                 .build()
133         ).when(orgn).json();
134         MatcherAssert.assertThat(
135             "Value is null",
136             new Organization.Smart(orgn).billingEmail(),
137             Matchers.notNullValue()
138         );
139     }
140 
141     @Test
142     void fetchesPublicRepos() throws IOException {
143         final Organization orgn = Mockito.mock(Organization.class);
144         Mockito.doReturn(
145             Json.createObjectBuilder()
146                 .add("public_repos", 1)
147                 .build()
148         ).when(orgn).json();
149         MatcherAssert.assertThat(
150             "Value is null",
151             new Organization.Smart(orgn).publicRepos(),
152             Matchers.notNullValue()
153         );
154     }
155 
156     @Test
157     void fetchesPublicGists() throws IOException {
158         final Organization orgn = Mockito.mock(Organization.class);
159         Mockito.doReturn(
160             Json.createObjectBuilder()
161                 .add("public_gists", 1)
162                 .build()
163         ).when(orgn).json();
164         MatcherAssert.assertThat(
165             "Value is null",
166             new Organization.Smart(orgn).publicGists(),
167             Matchers.notNullValue()
168         );
169     }
170 
171     @Test
172     void fetchesFollowers() throws IOException {
173         final Organization orgn = Mockito.mock(Organization.class);
174         Mockito.doReturn(
175             Json.createObjectBuilder()
176                 .add("followers", 1)
177                 .build()
178         ).when(orgn).json();
179         MatcherAssert.assertThat(
180             "Value is null",
181             new Organization.Smart(orgn).followers(),
182             Matchers.notNullValue()
183         );
184     }
185 
186     @Test
187     void fetchesFollowing() throws IOException {
188         final Organization orgn = Mockito.mock(Organization.class);
189         Mockito.doReturn(
190             Json.createObjectBuilder()
191                 .add("following", 1)
192                 .build()
193         ).when(orgn).json();
194         MatcherAssert.assertThat(
195             "Value is null",
196             new Organization.Smart(orgn).following(),
197             Matchers.notNullValue()
198         );
199     }
200 
201     @Test
202     void fetchesHtmlUrl() throws IOException {
203         final Organization orgn = Mockito.mock(Organization.class);
204         Mockito.doReturn(
205             Json.createObjectBuilder()
206                 .add("html_url", "https://github.com/octocat")
207                 .build()
208         ).when(orgn).json();
209         MatcherAssert.assertThat(
210             "Value is null",
211             new Organization.Smart(orgn).htmlUrl(),
212             Matchers.notNullValue()
213         );
214     }
215 
216     @Test
217     void fetchesCreatedAt() throws IOException {
218         final Organization orgn = Mockito.mock(Organization.class);
219         Mockito.doReturn(
220             Json.createObjectBuilder()
221                 .add("created_at", "2008-01-14T04:33:35Z")
222                 .build()
223         ).when(orgn).json();
224         MatcherAssert.assertThat(
225             "Value is null",
226             new Organization.Smart(orgn).createdAt(),
227             Matchers.notNullValue()
228         );
229     }
230 
231     @Test
232     void fetchesType() throws IOException {
233         final Organization orgn = Mockito.mock(Organization.class);
234         Mockito.doReturn(
235             Json.createObjectBuilder()
236                 .add("type", "Organization")
237                 .build()
238         ).when(orgn).json();
239         MatcherAssert.assertThat(
240             "Value is null",
241             new Organization.Smart(orgn).type(),
242             Matchers.notNullValue()
243         );
244     }
245 }