Skip to content

Commit 82f3940

Browse files
committed
tests fix
1 parent 8be1f41 commit 82f3940

File tree

2 files changed

+237
-0
lines changed

2 files changed

+237
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package org.scm4j.commons.coords;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.fail;
5+
6+
import org.junit.Test;
7+
import org.scm4j.commons.Version;
8+
9+
import nl.jqno.equalsverifier.EqualsVerifier;
10+
11+
public class CoordsGradleTest {
12+
13+
@Test
14+
public void testCoords() {
15+
try {
16+
new CoordsGradle("");
17+
fail();
18+
} catch (IllegalArgumentException e) {
19+
}
20+
try {
21+
new CoordsGradle("no-artifactId");
22+
fail();
23+
} catch (IllegalArgumentException e) {
24+
}
25+
}
26+
27+
CoordsGradle dc(String coords) {
28+
return new CoordsGradle(coords);
29+
}
30+
31+
@Test
32+
public void testComment() {
33+
assertEquals("", dc("com.myproject:c1").getComment());
34+
assertEquals("#", dc("com.myproject:c1#").getComment());
35+
assertEquals(" # ", dc(" com.myproject:c1 # ").getComment());
36+
assertEquals("#...$ #", dc("com.myproject:c1#...$ #").getComment());
37+
}
38+
39+
@Test
40+
public void testExtension() {
41+
assertEquals("", dc("com.myproject:c1").getExtension());
42+
assertEquals("", dc("com.myproject:c1@").getExtension());
43+
assertEquals("ext", dc("com.myproject:c1@ext#qw").getExtension());
44+
assertEquals("ext@", dc("com.myproject:c1@ext@#qw").getExtension());
45+
}
46+
47+
@Test
48+
public void testClassifier() {
49+
assertEquals("", dc("com.myproject:c1").getClassifier());
50+
assertEquals("", dc("com.myproject:c1::").getClassifier());
51+
assertEquals("class", dc("com.myproject:c1::class:").getClassifier());
52+
}
53+
54+
@Test
55+
public void testToSting() {
56+
assertEquals("com.myproject:c1::dfgd@ext # comment", dc("com.myproject:c1::dfgd@ext # comment").toString());
57+
}
58+
59+
@Test
60+
public void testGroupId() {
61+
assertEquals("com.myproject", dc("com.myproject:c1:1.0.0").getGroupId());
62+
assertEquals("com.myproject", dc("com.myproject:c1").getGroupId());
63+
assertEquals(" com.myproject", dc(" com.myproject:c1").getGroupId());
64+
}
65+
66+
@Test
67+
public void testArtifactId() {
68+
assertEquals("c1", dc("com.myproject:c1:1.0.0").getArtifactId());
69+
assertEquals("c1", dc("com.myproject:c1").getArtifactId());
70+
assertEquals("c1", dc(" com.myproject:c1").getArtifactId());
71+
}
72+
73+
@Test
74+
public void testVersion() {
75+
assertEquals(new Version("1.0.0"), dc("com.myproject:c1:1.0.0").getVersion());
76+
assertEquals(new Version("1.0.0"), dc("com.myproject:c1:1.0.0#comment").getVersion());
77+
assertEquals(new Version("1.0.0"), dc("com.myproject:c1:1.0.0@ext #comment").getVersion());
78+
assertEquals(new Version(""), dc("com.myproject:c1::dfgd@ext #comment").getVersion());
79+
assertEquals(new Version("-SNAPSHOT"), dc("com.myproject:c1:-SNAPSHOT:dfgd@ext #comment").getVersion());
80+
}
81+
82+
@Test
83+
public void testEqualsAndHashCode() {
84+
EqualsVerifier
85+
.forClass(CoordsGradle.class)
86+
.withOnlyTheseFields("coordsStringNoComment")
87+
.usingGetClass()
88+
.verify();
89+
}
90+
91+
@Test
92+
public void testVersionChange() {
93+
assertEquals("eu.untill:JTerminal:12.13 # comment", new CoordsGradle("eu.untill:JTerminal: # comment").toString("12.13"));
94+
assertEquals("eu.untill:JTerminal:12.13:abc@efg # comment", new CoordsGradle("eu.untill:JTerminal::abc@efg # comment").toString("12.13"));
95+
assertEquals("eu.untill:JTerminal::abc@efg # comment", new CoordsGradle("eu.untill:JTerminal:12.13:abc@efg # comment").toString(""));
96+
assertEquals("eu.untill:JTerminal::# comment", new CoordsGradle("eu.untill:JTerminal:12.13:# comment").toString(""));
97+
assertEquals("eu.untill:JTerminal # comment", new CoordsGradle("eu.untill:JTerminal:12.13 # comment").toString(""));
98+
assertEquals("eu.untill:JTerminal # comment", new CoordsGradle("eu.untill:JTerminal # comment").toString(""));
99+
assertEquals("eu.untill:JTerminal:12.13 # comment", new CoordsGradle("eu.untill:JTerminal # comment").toString("12.13"));
100+
}
101+
102+
@Test
103+
public void testToStringNoComment() {
104+
assertEquals("com.myproject:c1:1.0.0", dc("com.myproject:c1:1.0.0#comment").toStringNoComment());
105+
assertEquals("com.myproject:c1:1.0.0@ext", dc("com.myproject:c1:1.0.0@ext # comment").toStringNoComment());
106+
assertEquals("com.myproject:c1::dfgd@ext", dc("com.myproject:c1::dfgd@ext # comment").toStringNoComment());
107+
assertEquals("com.myproject:c1:", dc("com.myproject:c1: # comment").toStringNoComment());
108+
}
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package org.scm4j.commons.coords;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.fail;
5+
6+
import org.junit.Test;
7+
import org.scm4j.commons.Version;
8+
9+
import nl.jqno.equalsverifier.EqualsVerifier;
10+
11+
public class CoordsMavenTest {
12+
13+
@Test
14+
public void testCoords() {
15+
try {
16+
new CoordsMaven("");
17+
fail();
18+
} catch (IllegalArgumentException e) {
19+
}
20+
try {
21+
new CoordsMaven("no-artifactId");
22+
fail();
23+
} catch (IllegalArgumentException e) {
24+
}
25+
}
26+
27+
@Test
28+
public void testComment() {
29+
assertEquals("", new CoordsMaven("com.myproject:c1:12.13").getComment());
30+
assertEquals("#", new CoordsMaven("com.myproject:c1:12.13#").getComment());
31+
assertEquals(" # ", new CoordsMaven(" com.myproject:c1:12.13 # ").getComment());
32+
assertEquals("#...$ #", new CoordsMaven("com.myproject:c1:12.13#...$ #").getComment());
33+
}
34+
35+
@Test
36+
public void testExtension() {
37+
assertEquals("ext", new CoordsMaven("com.myproject:c1:ext:12.13").getExtension());
38+
assertEquals("", new CoordsMaven("com.myproject:c1:12.13").getExtension());
39+
assertEquals("", new CoordsMaven("com.myproject:c1::12.13").getExtension());
40+
assertEquals("", new CoordsMaven("com.myproject:c1:::12.13").getExtension());
41+
assertEquals("", new CoordsMaven("com.myproject:c1").getExtension());
42+
assertEquals("", new CoordsMaven("com.myproject:c1:").getExtension());
43+
assertEquals("", new CoordsMaven("com.myproject:c1::").getExtension());
44+
assertEquals("", new CoordsMaven("com.myproject:c1:::").getExtension());
45+
assertEquals("ext", new CoordsMaven("com.myproject:c1:ext:class:12.13").getExtension());
46+
assertEquals("ext@", new CoordsMaven("com.myproject:c1:ext@:12.13#qw").getExtension());
47+
}
48+
49+
@Test
50+
public void testClassifier() {
51+
assertEquals("class", new CoordsMaven("com.myproject:c1:ext:class:12.13 # comment").getClassifier());
52+
assertEquals("class", new CoordsMaven("com.myproject:c1::class:12.13 # comment").getClassifier());
53+
assertEquals("", new CoordsMaven("com.myproject:c1:12.13 # comment").getClassifier());
54+
assertEquals("", new CoordsMaven("com.myproject:c1:ext:12.13 # comment").getClassifier());
55+
assertEquals("", new CoordsMaven("com.myproject:c1:ext::12.13 # comment").getClassifier());
56+
assertEquals("", new CoordsMaven("com.myproject:c1:ext:: # comment").getClassifier());
57+
assertEquals("", new CoordsMaven("com.myproject:c1:ext: # comment").getClassifier());
58+
assertEquals("", new CoordsMaven("com.myproject:c1:ext # comment").getClassifier());
59+
assertEquals("", new CoordsMaven("com.myproject:c1:12.13 # comment").getClassifier());
60+
assertEquals("", new CoordsMaven("com.myproject:c1::12.13 # comment").getClassifier());
61+
assertEquals("", new CoordsMaven("com.myproject:c1:::12.13 # comment").getClassifier());
62+
}
63+
64+
@Test
65+
public void testToSting() {
66+
assertEquals("com.myproject:c1:ext:class:1.0.0 # comment",
67+
new CoordsMaven("com.myproject:c1:ext:class:1.0.0 # comment").toString());
68+
}
69+
70+
@Test
71+
public void testGroupId() {
72+
assertEquals("com.myproject", new CoordsMaven("com.myproject:c1:1.0.0").getGroupId());
73+
assertEquals("com.myproject", new CoordsMaven("com.myproject:c1:12.13").getGroupId());
74+
assertEquals(" com.myproject", new CoordsMaven(" com.myproject:c1:12.13").getGroupId());
75+
}
76+
77+
@Test
78+
public void testArtifactId() {
79+
assertEquals("c1", new CoordsMaven("com.myproject:c1:1.0.0").getArtifactId());
80+
assertEquals("c1", new CoordsMaven("com.myproject:c1").getArtifactId());
81+
assertEquals("c1", new CoordsMaven("com.myproject:c1:").getArtifactId());
82+
assertEquals("c1", new CoordsMaven("com.myproject:c1::").getArtifactId());
83+
assertEquals("c1", new CoordsMaven("com.myproject:c1:::").getArtifactId());
84+
assertEquals("c1", new CoordsMaven(" com.myproject:c1").getArtifactId());
85+
}
86+
87+
@Test
88+
public void testVersion() {
89+
assertEquals(new Version("1.0.0"), new CoordsMaven("com.myproject:c1:1.0.0").getVersion());
90+
assertEquals(new Version("1.0.0"), new CoordsMaven("com.myproject:c1::1.0.0#comment").getVersion());
91+
assertEquals(new Version("1.0.0"), new CoordsMaven("com.myproject:c1:::1.0.0#comment").getVersion());
92+
assertEquals(new Version(""), new CoordsMaven("com.myproject:c1 #comment").getVersion());
93+
assertEquals(new Version(""), new CoordsMaven("com.myproject:c1: #comment").getVersion());
94+
assertEquals(new Version(""), new CoordsMaven("com.myproject:c1:: #comment").getVersion());
95+
assertEquals(new Version(""), new CoordsMaven("com.myproject:c1::: #comment").getVersion());
96+
assertEquals(new Version("-SNAPSHOT"), new CoordsMaven("com.myproject:c1:ext:class:-SNAPSHOT #comment").getVersion());
97+
}
98+
99+
@Test
100+
public void testEqualsAndHashCode() {
101+
EqualsVerifier
102+
.forClass(CoordsMaven.class)
103+
.withOnlyTheseFields("coordsStringNoComment")
104+
.usingGetClass()
105+
.verify();
106+
}
107+
108+
@Test
109+
public void testVersionChange() {
110+
assertEquals("com.myproject:c1:12.13", new CoordsMaven("com.myproject:c1:1.0.0").toString("12.13"));
111+
assertEquals("com.myproject:c1::12.13#comment", new CoordsMaven("com.myproject:c1::1.0.0#comment").toString("12.13"));
112+
assertEquals("com.myproject:c1:::12.13#comment", new CoordsMaven("com.myproject:c1:::1.0.0#comment").toString("12.13"));
113+
assertEquals("com.myproject:c1:12.13 #comment", new CoordsMaven("com.myproject:c1 #comment").toString("12.13"));
114+
assertEquals("com.myproject:c1:12.13 #comment", new CoordsMaven("com.myproject:c1: #comment").toString("12.13"));
115+
assertEquals("com.myproject:c1::12.13 #comment", new CoordsMaven("com.myproject:c1:: #comment").toString("12.13"));
116+
assertEquals("com.myproject:c1:::12.13 #comment", new CoordsMaven("com.myproject:c1::: #comment").toString("12.13"));;
117+
assertEquals("com.myproject:c1:ext:class:12.13 #comment", new CoordsMaven("com.myproject:c1:ext:class:-SNAPSHOT #comment").toString("12.13"));
118+
}
119+
120+
@Test
121+
public void testToStringNoComment() {
122+
assertEquals("com.myproject:c1:12.13", new CoordsMaven("com.myproject:c1:12.13").toStringNoComment());
123+
assertEquals("com.myproject:c1:12.13", new CoordsMaven("com.myproject:c1:12.13#").toStringNoComment());
124+
assertEquals(" com.myproject:c1:12.13", new CoordsMaven(" com.myproject:c1:12.13 # ").toStringNoComment());
125+
assertEquals("com.myproject:c1:12.13", new CoordsMaven("com.myproject:c1:12.13#...$ #").toStringNoComment());
126+
}
127+
128+
}

0 commit comments

Comments
 (0)