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.Coordinates;
8   import com.jcabi.github.Repo;
9   import java.io.IOException;
10  import org.hamcrest.MatcherAssert;
11  import org.hamcrest.Matchers;
12  import org.junit.jupiter.api.Test;
13  
14  /**
15   * Test case for {@link MkBranch}.
16   * @since 0.1
17   */
18  final class MkBranchTest {
19      /**
20       * MkBranch can fetch its name.
21       * @throws IOException If an I/O problem occurs
22       */
23      @Test
24      void fetchesName() throws IOException {
25          final String name = "topic";
26          MatcherAssert.assertThat(
27              "Values are not equal",
28              MkBranchTest.branches(new MkGitHub().randomRepo())
29                  .create(name, "f8dfc75138a2b57859b65cfc45239978081b8de4")
30                  .name(),
31              Matchers.equalTo(name)
32          );
33      }
34  
35      /**
36       * MkBranch can fetch its commit.
37       * @throws IOException If an I/O problem occurs
38       */
39      @Test
40      void fetchesCommit() throws IOException {
41          final String sha = "ad1298cac285d601cd66b37ec8989836d7c6e651";
42          MatcherAssert.assertThat(
43              "Values are not equal",
44              MkBranchTest.branches(new MkGitHub().randomRepo())
45                  .create("feature-branch", sha).commit().sha(),
46              Matchers.equalTo(sha)
47          );
48      }
49  
50      /**
51       * MkBranch can fetch its repo.
52       * @throws IOException If an I/O problem occurs
53       */
54      @Test
55      void fetchesRepo() throws IOException {
56          final Repo repo = new MkGitHub().randomRepo();
57          final Coordinates coords = MkBranchTest.branches(repo)
58              .create("test", "sha")
59              .repo().coordinates();
60          MatcherAssert.assertThat(
61              "Values are not equal",
62              coords.user(),
63              Matchers.equalTo(repo.coordinates().user())
64          );
65          MatcherAssert.assertThat(
66              "Values are not equal",
67              coords.repo(),
68              Matchers.equalTo(repo.coordinates().repo())
69          );
70      }
71  
72      /**
73       * MkBranches for MkBranch creation.
74       * @param repo Repository to get MkBranches of
75       * @return MkBranches
76       */
77      private static MkBranches branches(final Repo repo) {
78          return (MkBranches) repo.branches();
79      }
80  }