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.Repo;
8   import com.jcabi.github.Repos;
9   import com.jcabi.github.Search;
10  import java.io.IOException;
11  import java.util.EnumMap;
12  import org.hamcrest.MatcherAssert;
13  import org.hamcrest.Matchers;
14  import org.junit.jupiter.api.Test;
15  
16  /**
17   * Test case for {@link MkSearch}.
18   * @since 0.1
19   * @checkstyle MultipleStringLiteralsCheck (100 lines)
20   */
21  @SuppressWarnings("PMD.AvoidDuplicateLiterals")
22  final class MkSearchTest {
23  
24      @Test
25      void canSearchForRepos() throws IOException {
26          final MkGitHub github = new MkGitHub();
27          github.repos().create(
28              new Repos.RepoCreate("TestRepo", false)
29          );
30          MatcherAssert.assertThat(
31              "Collection is not empty",
32              github.search().repos("TestRepo", "updated", Search.Order.ASC),
33              Matchers.not(Matchers.emptyIterable())
34          );
35      }
36  
37      @Test
38      void canSearchForIssues() throws IOException {
39          final MkGitHub github = new MkGitHub();
40          final Repo repo = github.repos().create(
41              new Repos.RepoCreate("TestIssues", false)
42          );
43          repo.issues().create("test issue", "TheTest");
44          MatcherAssert.assertThat(
45              "Collection is not empty",
46              github.search().issues(
47                  "TheTest",
48                  "updated",
49                  Search.Order.DESC,
50                  new EnumMap<>(Search.Qualifier.class)
51              ),
52              Matchers.not(Matchers.emptyIterable())
53          );
54      }
55  
56      @Test
57      void canSearchForUsers() throws IOException {
58          final MkGitHub github = new MkGitHub("jeff");
59          github.users().self();
60          MatcherAssert.assertThat(
61              "Collection is not empty",
62              github.search().users("jeff", "repositories", Search.Order.DESC),
63              Matchers.not(Matchers.emptyIterable())
64          );
65      }
66  
67      @Test
68      void canSearchForCodes() throws IOException {
69          final MkGitHub github = new MkGitHub("jeff");
70          github.repos().create(
71              new Repos.RepoCreate("TestCode", false)
72          );
73          MatcherAssert.assertThat(
74              "Collection is not empty",
75              github.search().codes("jeff", "repositories", Search.Order.DESC),
76              Matchers.not(Matchers.emptyIterable())
77          );
78      }
79  }