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 org.hamcrest.MatcherAssert;
33 import org.hamcrest.Matchers;
34 import org.junit.Test;
35
36 /**
37 * Test case for {@link Coordinates}.
38 * @author Volodya Lombrozo (volodya.lombrozo@gmail.com)
39 * @version $Id: 860924ba736eea5c525d75e60c695d58b589a85f $
40 */
41 public final class CoordinatesTest {
42
43 /**
44 * Coordinates.Https can retrieve user and repo from https coordinates.
45 */
46 @Test
47 public void retrievesUserAndRepoFromHttpsCoordinates() {
48 final Coordinates coords = new Coordinates.Https(
49 "https://github.com/yegor256/takes.git"
50 );
51 final String repo = "takes";
52 final String user = "yegor256";
53 MatcherAssert.assertThat(
54 String.format(
55 "Repo is retrieved incorrectly, we expect '%s', but was '%s'",
56 repo,
57 coords.repo()
58 ),
59 coords.repo(),
60 Matchers.equalTo(repo)
61 );
62 MatcherAssert.assertThat(
63 String.format(
64 "User is retrieved incorrectly, we expect '%s', but was '%s'",
65 user,
66 coords.user()
67 ),
68 coords.user(),
69 Matchers.equalTo(user)
70 );
71 }
72
73 /**
74 * Coordinates.Https equal if they have the same url.
75 */
76 @Test
77 public void sameHttpsCoordinatesAreEqual() {
78 final String same = "https://github.com/apache/tomcat.git";
79 MatcherAssert.assertThat(
80 "Same coordinates are equal",
81 new Coordinates.Https(same),
82 Matchers.equalTo(new Coordinates.Https(same))
83 );
84 }
85
86 /**
87 * Coordinates.Https can be compared.
88 */
89 @Test
90 public void comparesHttpsCoordinates() {
91 final String first = "https://github.com/apache/kafka.git";
92 final String second = "https://github.com/jcabi/jcabi-github";
93 final int difference = 9;
94 MatcherAssert.assertThat(
95 "First coordinates are less than second",
96 new Coordinates.Https(first)
97 .compareTo(new Coordinates.Https(second)),
98 Matchers.equalTo(-difference)
99 );
100 MatcherAssert.assertThat(
101 "Second coordinates are greater than first",
102 new Coordinates.Https(second)
103 .compareTo(new Coordinates.Https(first)),
104 Matchers.equalTo(difference)
105 );
106 MatcherAssert.assertThat(
107 "Same https coordinates are equal",
108 new Coordinates.Https(first)
109 .compareTo(new Coordinates.Https(first)),
110 Matchers.equalTo(0)
111 );
112 }
113
114 /**
115 * Coordinates.Simple can be compared with Coordinates.Https.
116 */
117 @Test
118 public void comparesSimpleAndHttpsCoordinates() {
119 MatcherAssert.assertThat(
120 "Coordinates should be equal",
121 new Coordinates.Simple("volodya-lombrozo/jtcop")
122 .compareTo(
123 new Coordinates.Https(
124 "https://github.com/volodya-lombrozo/jtcop"
125 )
126 ),
127 Matchers.equalTo(0)
128 );
129 }
130 }