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.aspects.Tv; 33 import com.jcabi.github.Github; 34 import com.jcabi.github.Issue; 35 import com.jcabi.github.Repo; 36 import com.jcabi.github.Repos; 37 import com.jcabi.immutable.ArrayMap; 38 import org.hamcrest.MatcherAssert; 39 import org.hamcrest.Matchers; 40 import org.junit.Test; 41 42 /** 43 * Test case for {@link MkIssues}. 44 * @author Yegor Bugayenko (yegor256@gmail.com) 45 * @version $Id: 0527fb8e4c622779341f3af6777380956cc61c41 $ 46 * @checkstyle MultipleStringLiterals (500 lines) 47 */ 48 public final class MkIssuesTest { 49 50 /** 51 * MkIssues can list issues. 52 * @throws Exception If some problem inside 53 */ 54 @Test 55 public void iteratesIssues() throws Exception { 56 final Repo repo = new MkGithub().randomRepo(); 57 repo.issues().create("hey, you", "body of issue"); 58 repo.issues().create("hey", "body of 2nd issue"); 59 repo.issues().create("hey again", "body of 3rd issue"); 60 MatcherAssert.assertThat( 61 repo.issues().iterate(new ArrayMap<>()), 62 Matchers.<Issue>iterableWithSize(Tv.THREE) 63 ); 64 } 65 66 /** 67 * MkIssues can create a new issue with correct author. 68 * @throws Exception If some problem inside 69 */ 70 @Test 71 public void createsNewIssueWithCorrectAuthor() throws Exception { 72 final Repo repo = new MkGithub().randomRepo(); 73 final Issue.Smart issue = new Issue.Smart( 74 repo.issues().create("hello", "the body") 75 ); 76 MatcherAssert.assertThat( 77 issue.author().login(), 78 Matchers.equalTo(repo.github().users().self().login()) 79 ); 80 } 81 82 /** 83 * MkIssues can create a multiple issues. 84 * @throws Exception If some problem inside 85 */ 86 @Test 87 public void createsMultipleIssues() throws Exception { 88 final Github github = new MkGithub("jeff"); 89 final Repo repo = github.repos().create( 90 new Repos.RepoCreate("test-3", false) 91 ); 92 for (int idx = 1; idx < Tv.TEN; ++idx) { 93 repo.issues().create("title", "body"); 94 } 95 } 96 }