View Javadoc
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.google.common.base.Optional;
33  import org.hamcrest.MatcherAssert;
34  import org.hamcrest.Matchers;
35  import org.junit.Test;
36  
37  /**
38   * Test case for {@link RtCommitsComparison}.
39   * @author Chris Rebert (github@chrisrebert.com)
40   * @version $Id: fb7bfdf82f8b0b57ea0fa9c54a7f3a6a7b7ea8ae $
41   * @since 0.24
42   */
43  public final class RtCommitsComparisonITCase {
44      /**
45       * RtCommitsComparison can read the file changes in the comparison.
46       * @throws Exception If some problem inside
47       * @see <a href="https://api.github.com/repos/jcabi/jcabi-github/compare/fec537c74da115b01a5c27b225d22a3976545acf...3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4">The relevant commit comparison</a>
48       */
49      @Test
50      public void readsFiles() throws Exception {
51          final String headsha = "3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4";
52          final Iterable<FileChange> files = new GithubIT().connect()
53              .repos()
54              .get(new Coordinates.Simple("jcabi/jcabi-github"))
55              .commits()
56              .compare("fec537c74da115b01a5c27b225d22a3976545acf", headsha)
57              .files();
58          MatcherAssert.assertThat(
59              files,
60              Matchers.<FileChange>iterableWithSize(1)
61          );
62          final FileChange.Smart file = new FileChange.Smart(
63              files.iterator().next()
64          );
65          MatcherAssert.assertThat(
66              file.additions(),
67              Matchers.equalTo(2)
68          );
69          MatcherAssert.assertThat(
70              file.blobUrl(),
71              Matchers.equalTo(
72                  // @checkstyle LineLength (1 line)
73                  "https://github.com/jcabi/jcabi-github/blob/3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4/.rultor.yml"
74              )
75          );
76          MatcherAssert.assertThat(
77              file.changes(),
78              // @checkstyle MagicNumberCheck (1 line)
79              Matchers.equalTo(4)
80          );
81          MatcherAssert.assertThat(
82              file.contentsUrl(),
83              Matchers.equalTo(
84                  // @checkstyle LineLength (1 line)
85                  "https://api.github.com/repos/jcabi/jcabi-github/contents/.rultor.yml?ref=3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4"
86              )
87          );
88          MatcherAssert.assertThat(
89              file.deletions(),
90              Matchers.equalTo(2)
91          );
92          MatcherAssert.assertThat(
93              file.filename(),
94              Matchers.equalTo(".rultor.yml")
95          );
96          MatcherAssert.assertThat(
97              file.patch(),
98              Matchers.equalTo(
99                  Optional.of(
100                     // @checkstyle LineLength (1 line)
101                     "@@ -2,7 +2,7 @@ architect:\n - yegor256\n - dmarkov\n install:\n-- sudo gem install -N pdd\n+- sudo gem install --no-rdoc --no-ri pdd\n assets:\n   secring.gpg: yegor256/home#assets/secring.gpg\n   settings.xml: yegor256/home#assets/jcabi/settings.xml\n@@ -37,4 +37,4 @@ release:\n     git commit -am \"${tag}\"\n     mvn clean deploy -Pqulice -Psonatype -Pjcabi --errors --settings ../settings.xml\n     mvn clean site-deploy -Psite --errors --settings ../settings.xml\n-  commanders: []\n\\ No newline at end of file\n+  commanders: []"
102                 )
103             )
104         );
105         MatcherAssert.assertThat(
106             file.rawUrl(),
107             Matchers.equalTo(
108                 // @checkstyle LineLength (1 line)
109                 "https://github.com/jcabi/jcabi-github/raw/3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4/.rultor.yml"
110             )
111         );
112         MatcherAssert.assertThat(
113             file.sha(),
114             Matchers.equalTo("daaa16ef7a19c2071ce80a6545077c11880daac3")
115         );
116         MatcherAssert.assertThat(
117             file.status(),
118             Matchers.equalTo(FileChange.Status.MODIFIED)
119         );
120     }
121 
122 }