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.mock; 31 32 import com.jcabi.github.PullRef; 33 import com.jcabi.github.Repo; 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 MkPullRef}. 41 * 42 * @author Chris Rebert (github@rebertia.com) 43 * @version $Id: c3bd8cfc85fd1a4154593899b79670178c0fca47 $ 44 * @since 0.24 45 */ 46 public final class MkPullRefTest { 47 /** 48 * Test ref. 49 */ 50 private static final String REF = "awesome-branch"; 51 /** 52 * Test commit SHA. 53 */ 54 private static final String SHA = 55 "361bb23ed4c028914d45d53c3727c48b035ee643"; 56 /** 57 * Test username. 58 */ 59 private static final String USERNAME = "myrtle"; 60 61 /** 62 * MkPullRef can fetch its repo. 63 * @throws IOException If there is an I/O problem 64 */ 65 @Test 66 public void fetchesRepo() throws IOException { 67 final MkStorage storage = new MkStorage.InFile(); 68 final Repo repo = new MkGithub(storage, MkPullRefTest.USERNAME) 69 .randomRepo(); 70 MatcherAssert.assertThat( 71 MkPullRefTest.pullRef(storage, repo).repo().coordinates(), 72 Matchers.equalTo(repo.coordinates()) 73 ); 74 } 75 76 /** 77 * MkPullRef can fetch its ref name. 78 * @throws IOException If there is an I/O problem 79 */ 80 @Test 81 public void fetchesRef() throws IOException { 82 MatcherAssert.assertThat( 83 pullRef().ref(), 84 Matchers.equalTo(MkPullRefTest.REF) 85 ); 86 } 87 88 /** 89 * MkPullRef can fetch its commit sha. 90 * @throws IOException If there is an I/O problem 91 */ 92 @Test 93 public void fetchesSha() throws IOException { 94 MatcherAssert.assertThat( 95 pullRef().sha(), 96 Matchers.equalTo(MkPullRefTest.SHA) 97 ); 98 } 99 100 /** 101 * Returns an MkPullRef for testing. 102 * @return MkPullRef for testing 103 * @throws IOException If there is an I/O problem 104 */ 105 private static PullRef pullRef() throws IOException { 106 final MkStorage storage = new MkStorage.InFile(); 107 return new MkPullRef( 108 storage, 109 ((MkBranches) new MkGithub(storage, MkPullRefTest.USERNAME) 110 .randomRepo() 111 .branches()).create(MkPullRefTest.REF, MkPullRefTest.SHA) 112 ); 113 } 114 115 /** 116 * Returns a pull request ref for testing. 117 * @param storage Storage 118 * @param repo Repo to create the pull request ref in 119 * @return PullRef for testing 120 * @throws IOException If there is an I/O problem 121 */ 122 private static PullRef pullRef( 123 final MkStorage storage, 124 final Repo repo 125 ) throws IOException { 126 return new MkPullRef( 127 storage, 128 ((MkBranches) repo.branches()) 129 .create(MkPullRefTest.REF, MkPullRefTest.SHA) 130 ); 131 } 132 }