View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github.mock;
6   
7   import com.jcabi.github.GitHub;
8   import com.jcabi.github.Organizations;
9   import java.io.IOException;
10  import java.text.ParseException;
11  import java.util.Date;
12  import java.util.concurrent.TimeUnit;
13  import org.hamcrest.MatcherAssert;
14  import org.hamcrest.Matchers;
15  import org.junit.jupiter.api.Test;
16  
17  /**
18   * GitHub organizations.
19   * @see <a href="https://developer.github.com/v3/orgs/">Organizations API</a>
20   * @since 0.24
21   */
22  final class MkOrganizationsTest {
23      @Test
24      void getSingleOrganization() throws IOException {
25          final String login = "orgTestGet";
26          final MkOrganizations orgs = new MkOrganizations(
27              new MkStorage.InFile()
28          );
29          MatcherAssert.assertThat(
30              "Value is null",
31              orgs.get(login),
32              Matchers.notNullValue()
33          );
34          MatcherAssert.assertThat(
35              "Values are not equal",
36              orgs.get(login).json().getString("login"),
37              Matchers.equalTo(login)
38          );
39      }
40  
41      @Test
42      void testCreatedAt() throws IOException, ParseException, InterruptedException {
43          final String name = "testCreatedAt";
44          final MkOrganizations orgs = new MkOrganizations(
45              new MkStorage.InFile()
46          );
47          final String created = "created_at";
48          final Date early = new GitHub.Time(
49              orgs.get(name)
50                  .json()
51                  .getString(created)
52          ).date();
53          TimeUnit.SECONDS.sleep(1L);
54          final Date later = new GitHub.Time(
55              orgs.get(name)
56                  .json()
57                  .getString(created)
58          ).date();
59          MatcherAssert.assertThat(
60              "Value is not greater than expected",
61              later,
62              Matchers.greaterThanOrEqualTo(early)
63          );
64      }
65  
66      /**
67       * MkOrganizations can list the logged-in user's organizations.
68       */
69      @Test
70      void iteratesCurrentUserOrganizations() throws IOException {
71          final Organizations orgs = new MkGitHub().organizations();
72          orgs.get("orgTestIterate");
73          MatcherAssert.assertThat(
74              "Collection is not empty",
75              orgs.iterate(),
76              Matchers.not(Matchers.emptyIterable())
77          );
78      }
79  }