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 java.io.IOException;
8   import org.hamcrest.MatcherAssert;
9   import org.hamcrest.Matchers;
10  import org.junit.jupiter.api.Assumptions;
11  import org.junit.jupiter.api.Test;
12  
13  /**
14   * Integration case for {@link GitHub}.
15   * @since 0.1
16   * @checkstyle ClassDataAbstractionCoupling (500 lines)
17   */
18  @OAuthScope(OAuthScope.Scope.REPO)
19  final class RtGitHubITCase {
20  
21      @Test
22      void authenticatesItself() {
23          final GitHub github = GitHubIT.connect();
24          MatcherAssert.assertThat(
25              "Value is null",
26              github.users().self(),
27              Matchers.notNullValue()
28          );
29      }
30  
31      @Test
32      void connectsAnonymously() throws IOException {
33          final GitHub github = new RtGitHub();
34          MatcherAssert.assertThat(
35              "Value is null",
36              new Issue.Smart(
37                  github.repos().get(
38                      new Coordinates.Simple("jcabi/jcabi-github")
39                  ).issues().get(1)
40              ).title(),
41              Matchers.notNullValue()
42          );
43      }
44  
45      @Test
46      void fetchesMeta() throws IOException {
47          final GitHub github = new RtGitHub();
48          MatcherAssert.assertThat(
49              "Collection is not empty",
50              github.meta().getJsonArray("hooks"),
51              Matchers.not(Matchers.empty())
52          );
53      }
54  
55      @Test
56      void fetchesEmojis() throws IOException {
57          final GitHub github = new RtGitHub();
58          MatcherAssert.assertThat(
59              "Values are not equal",
60              github.emojis().getString("+1"),
61              Matchers.startsWith("https://")
62          );
63      }
64  
65      @Test
66      void authenticatesWithUsernameAndPassword() throws IOException {
67          final String user = System.getProperty("failsafe.github.user");
68          final String password = System.getProperty("failsafe.github.password");
69          Assumptions.assumeTrue(
70              user != null && !user.isBlank(),
71              "GitHub user is required for this test"
72          );
73          Assumptions.assumeTrue(
74              password != null && !password.isBlank(),
75              "GitHub password is required for this test"
76          );
77          final GitHub github = new RtGitHub(user, password);
78          MatcherAssert.assertThat(
79              "Values are not equal",
80              new User.Smart(github.users().self()).login(),
81              Matchers.is(user)
82          );
83      }
84  
85      @Test
86      void fetchesUsers() {
87          final GitHub github = GitHubIT.connect();
88          MatcherAssert.assertThat(
89              "Iterating over github.users() should return something",
90              github.users().iterate("").iterator().next(),
91              Matchers.anything()
92          );
93      }
94  
95  }