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;
31
32 import com.jcabi.github.mock.MkGithub;
33 import com.jcabi.http.request.FakeRequest;
34 import org.hamcrest.MatcherAssert;
35 import org.hamcrest.Matchers;
36 import org.junit.Test;
37
38 /**
39 * Test case for {@link RtBranch}.
40 *
41 * @author Chris Rebert (github@rebertia.com)
42 * @version $Id: 76d0b55f017c75a69008b889417ff35b162e490a $
43 */
44 public final class RtBranchTest {
45 /**
46 * Test branch name.
47 */
48 private static final String BRANCH_NAME = "topic";
49 /**
50 * Commit SHA for test branch.
51 * @checkstyle LineLengthCheck (2 lines)
52 */
53 private static final String SHA = "b9b0b8a357bbf70f7c9f8ef17160ee31feb508a9";
54
55 /**
56 * RtBranch can fetch its commit.
57 * @throws Exception if a problem occurs.
58 */
59 @Test
60 public void fetchesCommit() throws Exception {
61 final Repo repo = new MkGithub().randomRepo();
62 final Commit commit = RtBranchTest.newBranch(repo).commit();
63 MatcherAssert.assertThat(commit.sha(), Matchers.equalTo(SHA));
64 final Coordinates coords = commit.repo().coordinates();
65 MatcherAssert.assertThat(
66 coords.user(),
67 Matchers.equalTo(repo.coordinates().user())
68 );
69 MatcherAssert.assertThat(
70 coords.repo(),
71 Matchers.equalTo(repo.coordinates().repo())
72 );
73 }
74
75 /**
76 * RtBranch can fetch its branch name.
77 * @throws Exception if a problem occurs.
78 */
79 @Test
80 public void fetchesName() throws Exception {
81 MatcherAssert.assertThat(
82 RtBranchTest.newBranch(new MkGithub().randomRepo()).name(),
83 Matchers.equalTo(BRANCH_NAME)
84 );
85 }
86
87 /**
88 * RtBranch can fetch its repo.
89 * @throws Exception if a problem occurs.
90 */
91 @Test
92 public void fetchesRepo() throws Exception {
93 final Repo repo = new MkGithub().randomRepo();
94 final Coordinates coords = RtBranchTest.newBranch(repo)
95 .repo().coordinates();
96 MatcherAssert.assertThat(
97 coords.user(),
98 Matchers.equalTo(repo.coordinates().user())
99 );
100 MatcherAssert.assertThat(
101 coords.repo(),
102 Matchers.equalTo(repo.coordinates().repo())
103 );
104 }
105
106 /**
107 * RtBranch for testing.
108 * @param repo Repository to create the branch in
109 * @return The RtBranch.
110 */
111 private static Branch newBranch(final Repo repo) {
112 return new RtBranch(
113 new FakeRequest(),
114 repo,
115 BRANCH_NAME,
116 SHA
117 );
118 }
119 }