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.PullRef;
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 MkPullRef}.
16   * @since 0.24
17   */
18  final class MkPullRefTest {
19      /**
20       * Test ref.
21       */
22      private static final String REF = "awesome-branch";
23  
24      /**
25       * Test commit SHA.
26       */
27      private static final String SHA =
28          "361bb23ed4c028914d45d53c3727c48b035ee643";
29  
30      /**
31       * Test username.
32       */
33      private static final String USERNAME = "myrtle";
34  
35      /**
36       * MkPullRef can fetch its repo.
37       * @throws IOException If there is an I/O problem
38       */
39      @Test
40      void fetchesRepo() throws IOException {
41          final MkStorage storage = new MkStorage.InFile();
42          final Repo repo = new MkGitHub(storage, MkPullRefTest.USERNAME)
43              .randomRepo();
44          MatcherAssert.assertThat(
45              "Values are not equal",
46              MkPullRefTest.pullRef(storage, repo).repo().coordinates(),
47              Matchers.equalTo(repo.coordinates())
48          );
49      }
50  
51      /**
52       * MkPullRef can fetch its ref name.
53       * @throws IOException If there is an I/O problem
54       */
55      @Test
56      void fetchesRef() throws IOException {
57          MatcherAssert.assertThat(
58              "Values are not equal",
59              MkPullRefTest.pullRef().ref(),
60              Matchers.equalTo(MkPullRefTest.REF)
61          );
62      }
63  
64      /**
65       * MkPullRef can fetch its commit sha.
66       * @throws IOException If there is an I/O problem
67       */
68      @Test
69      void fetchesSha() throws IOException {
70          MatcherAssert.assertThat(
71              "Values are not equal",
72              MkPullRefTest.pullRef().sha(),
73              Matchers.equalTo(MkPullRefTest.SHA)
74          );
75      }
76  
77      /**
78       * Returns an MkPullRef for testing.
79       * @return MkPullRef for testing
80       * @throws IOException If there is an I/O problem
81       */
82      private static PullRef pullRef() throws IOException {
83          final MkStorage storage = new MkStorage.InFile();
84          return new MkPullRef(
85              storage,
86              ((MkBranches) new MkGitHub(storage, MkPullRefTest.USERNAME)
87                  .randomRepo()
88                  .branches()).create(MkPullRefTest.REF, MkPullRefTest.SHA)
89          );
90      }
91  
92      /**
93       * Returns a pull request ref for testing.
94       * @param storage Storage
95       * @param repo Repo to create the pull request ref in
96       * @return PullRef for testing
97       * @throws IOException If there is an I/O problem
98       */
99      private static PullRef pullRef(
100         final MkStorage storage,
101         final Repo repo
102     ) throws IOException {
103         return new MkPullRef(
104             storage,
105             ((MkBranches) repo.branches())
106                 .create(MkPullRefTest.REF, MkPullRefTest.SHA)
107         );
108     }
109 }