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.CommitsComparison; 33 import com.jcabi.github.Coordinates; 34 import com.jcabi.github.RepoCommit; 35 import java.io.IOException; 36 import org.hamcrest.MatcherAssert; 37 import org.hamcrest.Matchers; 38 import org.junit.Test; 39 40 /** 41 * Test case for {@link MkCommitsComparison). 42 * @author Andrej Istomin (andrej.istomin.ikeen@gmail.com) 43 * @version $Id: de2c293a1df56104a25ae711c3cbd88270895fdd $ 44 */ 45 public final class MkCommitsComparisonTest { 46 47 /** 48 * MkCommitsComparison can get a repo. 49 * @throws IOException if some problem inside 50 */ 51 @Test 52 public void getRepo() throws IOException { 53 final String user = "test_user"; 54 MatcherAssert.assertThat( 55 new MkCommitsComparison( 56 new MkStorage.InFile(), user, 57 new Coordinates.Simple(user, "test_repo") 58 ).repo(), Matchers.notNullValue() 59 ); 60 } 61 /** 62 * MkCommitsComparison can get a JSON. 63 * @throws Exception if some problem inside 64 */ 65 @Test 66 public void canGetJson() throws Exception { 67 MatcherAssert.assertThat( 68 new MkCommitsComparison( 69 new MkStorage.InFile(), "test1", new Coordinates.Simple( 70 "test_user1", "test_repo1" 71 ) 72 ).json().getString("status"), 73 Matchers.notNullValue() 74 ); 75 MatcherAssert.assertThat( 76 new MkCommitsComparison( 77 new MkStorage.InFile(), "test2", new Coordinates.Simple( 78 "test_user2", "test_repo2" 79 ) 80 ).json().getInt("ahead_by"), 81 Matchers.notNullValue() 82 ); 83 } 84 85 /** 86 * MkCommitsComparison can get a JSON with commits. 87 * @throws Exception if some problem inside 88 */ 89 @Test 90 public void canGetJsonWithCommits() throws Exception { 91 final CommitsComparison cmp = new MkCommitsComparison( 92 new MkStorage.InFile(), "test-9", 93 new Coordinates.Simple("test_user_A", "test_repo_B") 94 ); 95 MatcherAssert.assertThat( 96 new CommitsComparison.Smart(cmp).commits(), 97 Matchers.<RepoCommit>iterableWithSize(0) 98 ); 99 MatcherAssert.assertThat( 100 cmp.json().getJsonArray("commits"), 101 Matchers.notNullValue() 102 ); 103 } 104 }