View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github;
6   
7   import com.google.common.base.Optional;
8   import java.io.IOException;
9   import org.hamcrest.MatcherAssert;
10  import org.hamcrest.Matchers;
11  import org.junit.jupiter.api.Test;
12  
13  /**
14   * Test case for {@link RtCommitsComparison}.
15   * @since 0.24
16   */
17  @SuppressWarnings("PMD.AvoidDuplicateLiterals")
18  final class RtCommitsComparisonITCase {
19      /**
20       * RtCommitsComparison can read the file changes in the comparison.
21       * @see <a href="https://api.github.com/repos/jcabi/jcabi-github/compare/fec537c74da115b01a5c27b225d22a3976545acf...3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4">The relevant commit comparison</a>
22       */
23      @Test
24      void readsFiles() throws IOException {
25          final String headsha = "3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4";
26          final Iterable<FileChange> files = GitHubIT.connect()
27              .repos()
28              .get(new Coordinates.Simple("jcabi/jcabi-github"))
29              .commits()
30              .compare("fec537c74da115b01a5c27b225d22a3976545acf", headsha)
31              .files();
32          MatcherAssert.assertThat(
33              "Collection size is incorrect",
34              files,
35              Matchers.iterableWithSize(1)
36          );
37          final FileChange.Smart file = new FileChange.Smart(
38              files.iterator().next()
39          );
40          MatcherAssert.assertThat(
41              "Values are not equal",
42              file.additions(),
43              Matchers.equalTo(2)
44          );
45          MatcherAssert.assertThat(
46              "Values are not equal",
47              file.blobUrl(),
48              Matchers.equalTo(
49                  // @checkstyle LineLength (1 line)
50                  "https://github.com/jcabi/jcabi-github/blob/3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4/.rultor.yml"
51              )
52          );
53          MatcherAssert.assertThat(
54              "Values are not equal",
55              file.changes(),
56              // @checkstyle MagicNumberCheck (1 line)
57              Matchers.equalTo(4)
58          );
59          MatcherAssert.assertThat(
60              "Values are not equal",
61              file.contentsUrl(),
62              Matchers.equalTo(
63                  // @checkstyle LineLength (1 line)
64                  "https://api.github.com/repos/jcabi/jcabi-github/contents/.rultor.yml?ref=3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4"
65              )
66          );
67          MatcherAssert.assertThat(
68              "Values are not equal",
69              file.deletions(),
70              Matchers.equalTo(2)
71          );
72          MatcherAssert.assertThat(
73              "Values are not equal",
74              file.filename(),
75              Matchers.equalTo(".rultor.yml")
76          );
77          MatcherAssert.assertThat(
78              "Values are not equal",
79              file.patch(),
80              Matchers.equalTo(
81                  Optional.of(
82                      // @checkstyle LineLength (1 line)
83                      "@@ -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: []"
84                  )
85              )
86          );
87          MatcherAssert.assertThat(
88              "Values are not equal",
89              file.rawUrl(),
90              Matchers.equalTo(
91                  // @checkstyle LineLength (1 line)
92                  "https://github.com/jcabi/jcabi-github/raw/3ebe52aaf7bf7681fa30a19fcbbbb246db7ad8b4/.rultor.yml"
93              )
94          );
95          MatcherAssert.assertThat(
96              "Values are not equal",
97              file.sha(),
98              Matchers.equalTo("daaa16ef7a19c2071ce80a6545077c11880daac3")
99          );
100         MatcherAssert.assertThat(
101             "Values are not equal",
102             file.status(),
103             Matchers.equalTo(FileChange.Status.MODIFIED)
104         );
105     }
106 
107 }