View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github;
6   
7   import com.jcabi.github.mock.MkGitHub;
8   import com.jcabi.http.request.FakeRequest;
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 RtBranch}.
16   * @since 0.8
17   */
18  @SuppressWarnings("PMD.AvoidDuplicateLiterals")
19  final class RtBranchTest {
20      /**
21       * Test branch name.
22       */
23      private static final String BRANCH_NAME = "topic";
24  
25      /**
26       * Commit SHA for test branch.
27       * @checkstyle LineLengthCheck (2 lines)
28       */
29      private static final String SHA = "b9b0b8a357bbf70f7c9f8ef17160ee31feb508a9";
30  
31      @Test
32      void fetchesCommit() throws IOException {
33          final Repo repo = new MkGitHub().randomRepo();
34          final Commit commit = RtBranchTest.newBranch(repo).commit();
35          MatcherAssert.assertThat(
36              "Values are not equal", commit.sha(), Matchers.equalTo(RtBranchTest.SHA)
37          );
38          final Coordinates coords = commit.repo().coordinates();
39          MatcherAssert.assertThat(
40              "Values are not equal",
41              coords.user(),
42              Matchers.equalTo(repo.coordinates().user())
43          );
44          MatcherAssert.assertThat(
45              "Values are not equal",
46              coords.repo(),
47              Matchers.equalTo(repo.coordinates().repo())
48          );
49      }
50  
51      @Test
52      void fetchesName() throws IOException {
53          MatcherAssert.assertThat(
54              "Values are not equal",
55              RtBranchTest.newBranch(new MkGitHub().randomRepo()).name(),
56              Matchers.equalTo(RtBranchTest.BRANCH_NAME)
57          );
58      }
59  
60      @Test
61      void fetchesRepo() throws IOException {
62          final Repo repo = new MkGitHub().randomRepo();
63          final Coordinates coords = RtBranchTest.newBranch(repo)
64              .repo().coordinates();
65          MatcherAssert.assertThat(
66              "Values are not equal",
67              coords.user(),
68              Matchers.equalTo(repo.coordinates().user())
69          );
70          MatcherAssert.assertThat(
71              "Values are not equal",
72              coords.repo(),
73              Matchers.equalTo(repo.coordinates().repo())
74          );
75      }
76  
77      /**
78       * RtBranch for testing.
79       * @param repo Repository to create the branch in
80       * @return The RtBranch.
81       */
82      private static Branch newBranch(final Repo repo) {
83          return new RtBranch(
84              new FakeRequest(),
85              repo,
86              RtBranchTest.BRANCH_NAME,
87              RtBranchTest.SHA
88          );
89      }
90  }