1 /**
2 * Copyright (c) 2013-2023, jcabi.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met: 1) Redistributions of source code must retain the above
8 * copyright notice, this list of conditions and the following
9 * disclaimer. 2) Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution. 3) Neither the name of the jcabi.com nor
13 * the names of its contributors may be used to endorse or promote
14 * products derived from this software without specific prior written
15 * permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package com.jcabi.github.mock;
31
32 import com.jcabi.github.Repo;
33 import com.jcabi.github.Repos;
34 import com.jcabi.github.Search;
35 import java.util.EnumMap;
36 import org.hamcrest.MatcherAssert;
37 import org.hamcrest.Matchers;
38 import org.junit.Test;
39
40 /**
41 * Test case for {@link MkSearch}.
42 *
43 * @author Carlos Miranda (miranda.cma@gmail.com)
44 * @version $Id: f8fd5e7a44987089d7f7c2141050b9407b11cf4d $
45 * @checkstyle MultipleStringLiteralsCheck (100 lines)
46 */
47 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
48 public final class MkSearchTest {
49
50 /**
51 * MkSearch can search for repos.
52 *
53 * @throws Exception if a problem occurs
54 */
55 @Test
56 public void canSearchForRepos() throws Exception {
57 final MkGithub github = new MkGithub();
58 github.repos().create(
59 new Repos.RepoCreate("TestRepo", false)
60 );
61 MatcherAssert.assertThat(
62 github.search().repos("TestRepo", "updated", Search.Order.ASC),
63 Matchers.not(Matchers.emptyIterable())
64 );
65 }
66
67 /**
68 * MkSearch can search for issues.
69 *
70 * @throws Exception if a problem occurs
71 */
72 @Test
73 public void canSearchForIssues() throws Exception {
74 final MkGithub github = new MkGithub();
75 final Repo repo = github.repos().create(
76 new Repos.RepoCreate("TestIssues", false)
77 );
78 repo.issues().create("test issue", "TheTest");
79 MatcherAssert.assertThat(
80 github.search().issues(
81 "TheTest",
82 "updated",
83 Search.Order.DESC,
84 new EnumMap<>(Search.Qualifier.class)
85 ),
86 Matchers.not(Matchers.emptyIterable())
87 );
88 }
89
90 /**
91 * MkSearch can search for users.
92 *
93 * @throws Exception if a problem occurs
94 */
95 @Test
96 public void canSearchForUsers() throws Exception {
97 final MkGithub github = new MkGithub("jeff");
98 github.users().self();
99 MatcherAssert.assertThat(
100 github.search().users("jeff", "repositories", Search.Order.DESC),
101 Matchers.not(Matchers.emptyIterable())
102 );
103 }
104
105 /**
106 * MkSearch can search for codes.
107 *
108 * @throws Exception if a problem occurs
109 */
110 @Test
111 public void canSearchForCodes() throws Exception {
112 final MkGithub github = new MkGithub("jeff");
113 github.repos().create(
114 new Repos.RepoCreate("TestCode", false)
115 );
116 MatcherAssert.assertThat(
117 github.search().codes("jeff", "repositories", Search.Order.DESC),
118 Matchers.not(Matchers.emptyIterable())
119 );
120 }
121 }