-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathInferConfigTest.java
More file actions
97 lines (86 loc) · 3.82 KB
/
InferConfigTest.java
File metadata and controls
97 lines (86 loc) · 3.82 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.javacs;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import org.junit.Test;
public class InferConfigTest {
private Path workspaceRoot = Paths.get("src/test/examples/maven-project");
private Path mavenHome = Paths.get("src/test/examples/home-dir/.m2");
private Path gradleHome = Paths.get("src/test/examples/home-dir/.gradle");
private Set<String> externalDependencies = Set.of("com.external:external-library:1.2");
private InferConfig both = new InferConfig(workspaceRoot, externalDependencies, mavenHome, gradleHome);
private InferConfig gradle = new InferConfig(workspaceRoot, externalDependencies, Paths.get("nowhere"), gradleHome);
private InferConfig thisProject = new InferConfig(Paths.get("."), Set.of());
@Test
public void mavenClassPath() {
assertThat(
both.classPath(),
contains(mavenHome.resolve("repository/com/external/external-library/1.2/external-library-1.2.jar")));
// v1.1 should be ignored
}
@Test
public void gradleClasspath() {
assertThat(
gradle.classPath(),
contains(
gradleHome.resolve(
"caches/modules-2/files-2.1/com.external/external-library/1.2/xxx/external-library-1.2.jar")));
// v1.1 should be ignored
}
@Test
public void mavenDocPath() {
assertThat(
both.buildDocPath(),
contains(
mavenHome.resolve(
"repository/com/external/external-library/1.2/external-library-1.2-sources.jar")));
// v1.1 should be ignored
}
@Test
public void gradleDocPath() {
assertThat(
gradle.buildDocPath(),
contains(
gradleHome.resolve(
"caches/modules-2/files-2.1/com.external/external-library/1.2/yyy/external-library-1.2-sources.jar")));
// v1.1 should be ignored
}
@Test
public void dependencyList() {
assertThat(InferConfig.mvnDependencies(Paths.get("pom.xml"), "dependency:list"), not(empty()));
}
@Test
public void thisProjectClassPath() {
assertThat(
thisProject.classPath(),
hasItem(hasToString(endsWith(".m2/repository/junit/junit/4.13.1/junit-4.13.1.jar"))));
}
@Test
public void thisProjectDocPath() {
assertThat(
thisProject.buildDocPath(),
hasItem(hasToString(endsWith(".m2/repository/junit/junit/4.13.1/junit-4.13.1-sources.jar"))));
}
@Test
public void parseDependencyLine() {
String[][] testCases = {
{
"[INFO] org.openjdk.jmh:jmh-generator-annprocess:jar:1.21:provided:/Users/georgefraser/.m2/repository/org/openjdk/jmh/jmh-generator-annprocess/1.21/jmh-generator-annprocess-1.21.jar",
"/Users/georgefraser/.m2/repository/org/openjdk/jmh/jmh-generator-annprocess/1.21/jmh-generator-annprocess-1.21.jar",
},
{
"[INFO] org.openjdk.jmh:jmh-generator-annprocess:jar:1.21:provided:/Users/georgefraser/.m2/repository/org/openjdk/jmh/jmh-generator-annprocess/1.21/jmh-generator-annprocess-1.21.jar -- module jmh.generator.annprocess (auto)",
"/Users/georgefraser/.m2/repository/org/openjdk/jmh/jmh-generator-annprocess/1.21/jmh-generator-annprocess-1.21.jar",
},
};
for (var pair : testCases) {
assert pair.length == 2;
var line = pair[0];
var expect = pair[1];
var path = InferConfig.readDependency(line);
assertThat(path, equalTo(Paths.get(expect)));
}
}
}