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 org.hamcrest.MatcherAssert;
8   import org.hamcrest.Matchers;
9   import org.junit.jupiter.api.Test;
10  
11  /**
12   * Test case for {@link Coordinates}.
13   * @since 0.1
14   */
15  final class CoordinatesTest {
16  
17      @Test
18      void retrievesUserAndRepoFromHttpsCoordinates() {
19          final Coordinates coords = new Coordinates.Https(
20              "https://github.com/yegor256/takes.git"
21          );
22          final String repo = "takes";
23          MatcherAssert.assertThat(
24              String.format(
25                  "Repo is retrieved incorrectly, we expect '%s', but was '%s'",
26                  repo,
27                  coords.repo()
28              ),
29              coords.repo(),
30              Matchers.equalTo(repo)
31          );
32          final String user = "yegor256";
33          MatcherAssert.assertThat(
34              String.format(
35                  "User is retrieved incorrectly, we expect '%s', but was '%s'",
36                  user,
37                  coords.user()
38              ),
39              coords.user(),
40              Matchers.equalTo(user)
41          );
42      }
43  
44      @Test
45      void sameHttpsCoordinatesAreEqual() {
46          final String same = "https://github.com/apache/tomcat.git";
47          MatcherAssert.assertThat(
48              "Same coordinates are equal",
49              new Coordinates.Https(same),
50              Matchers.equalTo(new Coordinates.Https(same))
51          );
52      }
53  
54      @Test
55      void comparesHttpsCoordinates() {
56          final String first = "https://github.com/apache/kafka.git";
57          final String second = "https://github.com/jcabi/jcabi-github";
58          final int difference = 9;
59          MatcherAssert.assertThat(
60              "First coordinates are less than second",
61              new Coordinates.Https(first)
62                  .compareTo(new Coordinates.Https(second)),
63              Matchers.equalTo(-difference)
64          );
65          MatcherAssert.assertThat(
66              "Second coordinates are greater than first",
67              new Coordinates.Https(second)
68                  .compareTo(new Coordinates.Https(first)),
69              Matchers.equalTo(difference)
70          );
71          MatcherAssert.assertThat(
72              "Same https coordinates are equal",
73              new Coordinates.Https(first)
74                  .compareTo(new Coordinates.Https(first)),
75              Matchers.equalTo(0)
76          );
77      }
78  
79      @Test
80      void comparesSimpleAndHttpsCoordinates() {
81          MatcherAssert.assertThat(
82              "Coordinates should be equal",
83              new Coordinates.Simple("volodya-lombrozo/jtcop")
84                  .compareTo(
85                      new Coordinates.Https(
86                          "https://github.com/volodya-lombrozo/jtcop"
87                      )
88                  ),
89              Matchers.equalTo(0)
90          );
91      }
92  }