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