1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
38
39
40
41 public final class CoordinatesTest {
42
43
44
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
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
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
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 }