View Javadoc
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.google.common.collect.Lists;
33  import com.jcabi.aspects.Tv;
34  import com.jcabi.github.Coordinates;
35  import com.jcabi.github.Language;
36  import com.jcabi.github.Milestones;
37  import com.jcabi.github.Repo;
38  import com.jcabi.github.Repos;
39  import java.io.IOException;
40  import org.hamcrest.MatcherAssert;
41  import org.hamcrest.Matchers;
42  import org.junit.Test;
43  
44  /**
45   * Test case for {@link Repo}.
46   * @author Yegor Bugayenko (yegor256@gmail.com)
47   * @version $Id: d29e51ef64d85c0a9d47e7c7c47536097ac1860e $
48   * @checkstyle MultipleStringLiterals (500 lines)
49   */
50  public final class MkRepoTest {
51  
52      /**
53       * Repo can work.
54       * @throws Exception If some problem inside
55       */
56      @Test
57      public void works() throws Exception {
58          final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
59          final Repo repo = repos.create(
60              new Repos.RepoCreate("test5", false)
61          );
62          MatcherAssert.assertThat(
63              repo.coordinates(),
64              Matchers.hasToString("jeff/test5")
65          );
66      }
67  
68      /**
69       * This tests that the milestones() method in MkRepo is working fine.
70       * @throws Exception - if anything goes wrong.
71       */
72      @Test
73      public void returnsMkMilestones() throws Exception {
74          final Repos repos = new MkRepos(new MkStorage.InFile(), "jeff");
75          final Repo repo = repos.create(
76              new Repos.RepoCreate("test1", false)
77          );
78          final Milestones milestones = repo.milestones();
79          MatcherAssert.assertThat(milestones, Matchers.notNullValue());
80      }
81  
82      /**
83       * Repo can fetch its commits.
84       *
85       * @throws IOException if some problem inside
86       */
87      @Test
88      public void fetchCommits() throws IOException {
89          final String user = "testuser";
90          final Repo repo = new MkRepo(
91              new MkStorage.InFile(),
92              user,
93              new Coordinates.Simple(user, "testrepo")
94          );
95          MatcherAssert.assertThat(repo.commits(), Matchers.notNullValue());
96      }
97  
98      /**
99       * Repo can fetch its branches.
100      *
101      * @throws IOException if some problem inside
102      */
103     @Test
104     public void fetchBranches() throws IOException {
105         final String user = "testuser";
106         final Repo repo = new MkRepo(
107             new MkStorage.InFile(),
108             user,
109             new Coordinates.Simple(user, "testrepo")
110         );
111         MatcherAssert.assertThat(repo.branches(), Matchers.notNullValue());
112     }
113 
114     /**
115      * Repo can exponse attributes.
116      * @throws Exception If some problem inside
117      */
118     @Test
119     public void exposesAttributes() throws Exception {
120         final Repo repo = new MkGithub().randomRepo();
121         MatcherAssert.assertThat(
122             new Repo.Smart(repo).description(),
123             Matchers.notNullValue()
124         );
125         MatcherAssert.assertThat(
126             new Repo.Smart(repo).isPrivate(),
127             Matchers.is(true)
128         );
129     }
130 
131     /**
132      * Repo can return Stars API.
133      * @throws IOException if some problem inside
134      */
135     @Test
136     public void fetchStars() throws IOException {
137         final String user = "testuser2";
138         final Repo repo = new MkRepo(
139             new MkStorage.InFile(),
140             user,
141             new Coordinates.Simple(user, "testrepo2")
142         );
143         MatcherAssert.assertThat(repo.stars(), Matchers.notNullValue());
144     }
145 
146     /**
147      * Repo can return Notifications API.
148      * @throws IOException if some problem inside
149      */
150     @Test
151     public void fetchNotifications() throws IOException {
152         final String user = "testuser3";
153         final Repo repo = new MkRepo(
154             new MkStorage.InFile(),
155             user,
156             new Coordinates.Simple(user, "testrepo3")
157         );
158         MatcherAssert.assertThat(repo.notifications(), Matchers.notNullValue());
159     }
160 
161     /**
162      * Repo can return Languages iterable.
163      * @throws IOException if some problem inside
164      */
165     @Test
166     public void fetchLanguages() throws IOException {
167         final String user = "testuser4";
168         final Repo repo = new MkRepo(
169             new MkStorage.InFile(),
170             user,
171             new Coordinates.Simple(user, "testrepo4")
172         );
173         final Iterable<Language> languages = repo.languages();
174         MatcherAssert.assertThat(languages, Matchers.notNullValue());
175         MatcherAssert.assertThat(
176             Lists.newArrayList(languages),
177             Matchers.hasSize(Tv.THREE)
178         );
179     }
180 
181     /**
182      * MkRepo can return its default branch.
183      * @throws IOException if some problem inside.
184      */
185     @Test
186     public void retrievesDefaultBranch() throws IOException {
187         final String user = "testuser5";
188         final Repo repo = new MkRepo(
189             new MkStorage.InFile(),
190             user,
191             new Coordinates.Simple(user, "testrepo5")
192         );
193         MatcherAssert.assertThat(
194             repo.defaultBranch().name(),
195             Matchers.equalTo("master")
196         );
197     }
198 }