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.util.EnumMap;
8   import java.util.Iterator;
9   import org.hamcrest.MatcherAssert;
10  import org.hamcrest.Matchers;
11  import org.junit.jupiter.api.Test;
12  
13  /**
14   * Test case for {@link RtSearch}.
15   * @since 0.1
16   * @checkstyle MultipleStringLiterals (140 lines)
17   */
18  @OAuthScope({ OAuthScope.Scope.REPO, OAuthScope.Scope.USER })
19  @SuppressWarnings("PMD.AvoidDuplicateLiterals")
20  final class RtSearchITCase {
21  
22      @Test
23      void canSearchForRepos() {
24          MatcherAssert.assertThat(
25              "Collection is not empty",
26              GitHubIT.connect()
27                  .search().repos("repo", "stars", Search.Order.DESC),
28              Matchers.not(Matchers.emptyIterableOf(Repo.class))
29          );
30      }
31  
32      /**
33       * RtSearch can fetch multiple pages of a large result (more than 25 items).
34       */
35      @Test
36      void canFetchMultiplePages() {
37          final Iterator<Repo> iter = GitHubIT.connect().search().repos(
38              "java", "", Search.Order.DESC
39          ).iterator();
40          int count = 0;
41          while (iter.hasNext() && count < 100) {
42              iter.next().coordinates();
43              count += 1;
44          }
45          MatcherAssert.assertThat(
46              "Value is not greater than expected",
47              count,
48              Matchers.greaterThanOrEqualTo(100)
49          );
50      }
51  
52      @Test
53      void canSearchForIssues() {
54          final EnumMap<Search.Qualifier, String> qualifiers =
55              new EnumMap<>(Search.Qualifier.class);
56          qualifiers.put(Search.Qualifier.LABEL, "bug");
57          MatcherAssert.assertThat(
58              "Collection is not empty",
59              GitHubIT.connect().search().issues(
60                  "qualifiers",
61                  "updated",
62                  Search.Order.DESC,
63                  qualifiers
64              ),
65              Matchers.not(Matchers.emptyIterableOf(Issue.class))
66          );
67      }
68  
69      @Test
70      void canSearchForUsers() {
71          MatcherAssert.assertThat(
72              "Collection is not empty",
73              GitHubIT.connect()
74                  .search().users("jcabi", "joined", Search.Order.DESC),
75              Matchers.not(Matchers.emptyIterableOf(User.class))
76          );
77      }
78  
79      /**
80       * RtSearch can search for contents.
81       * @see <a href="https://developer.github.com/v3/search/#search-code">Search API</a> for details
82       */
83      @Test
84      void canSearchForContents() {
85          MatcherAssert.assertThat(
86              "Collection is not empty",
87              GitHubIT.connect().search().codes(
88                  "addClass repo:jquery/jquery", "joined", Search.Order.DESC
89              ),
90              Matchers.not(Matchers.emptyIterableOf(Content.class))
91          );
92      }
93  
94  }