View Javadoc
1   /**
2    * Copyright (c) 2013-2022, 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.Coordinates;
33  import com.jcabi.github.Repo;
34  import java.io.IOException;
35  import org.hamcrest.MatcherAssert;
36  import org.hamcrest.Matchers;
37  import org.junit.Test;
38  
39  /**
40   * Test case for {@link MkBranch}.
41   *
42   * @author Chris Rebert (github@rebertia.com)
43   * @version $Id: 80b5961f530956393cdaf099ac6ffa7d7190ab3e $
44   */
45  public final class MkBranchTest {
46      /**
47       * MkBranch can fetch its name.
48       * @throws IOException If an I/O problem occurs
49       */
50      @Test
51      public void fetchesName() throws IOException {
52          final String name = "topic";
53          MatcherAssert.assertThat(
54              MkBranchTest.branches(new MkGithub().randomRepo())
55                  .create(name, "f8dfc75138a2b57859b65cfc45239978081b8de4")
56                  .name(),
57              Matchers.equalTo(name)
58          );
59      }
60  
61      /**
62       * MkBranch can fetch its commit.
63       * @throws IOException If an I/O problem occurs
64       */
65      @Test
66      public void fetchesCommit() throws IOException {
67          final String sha = "ad1298cac285d601cd66b37ec8989836d7c6e651";
68          MatcherAssert.assertThat(
69              MkBranchTest.branches(new MkGithub().randomRepo())
70                  .create("feature-branch", sha).commit().sha(),
71              Matchers.equalTo(sha)
72          );
73      }
74  
75      /**
76       * MkBranch can fetch its repo.
77       * @throws IOException If an I/O problem occurs
78       */
79      @Test
80      public void fetchesRepo() throws IOException {
81          final Repo repo = new MkGithub().randomRepo();
82          final Coordinates coords = MkBranchTest.branches(repo)
83              .create("test", "sha")
84              .repo().coordinates();
85          MatcherAssert.assertThat(
86              coords.user(),
87              Matchers.equalTo(repo.coordinates().user())
88          );
89          MatcherAssert.assertThat(
90              coords.repo(),
91              Matchers.equalTo(repo.coordinates().repo())
92          );
93      }
94  
95      /**
96       * MkBranches for MkBranch creation.
97       * @param repo Repository to get MkBranches of
98       * @return MkBranches
99       * @throws IOException If there is any I/O problem
100      */
101     private static MkBranches branches(final Repo repo) throws IOException {
102         return (MkBranches) (repo.branches());
103     }
104 }