package org.javacs; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; 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/test-project/workspace"); private Path mavenHome = Paths.get("src/test/test-project/home/.m2"); private Path gradleHome = Paths.get("src/test/test-project/home/.gradle"); private Set 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.12/junit-4.12.jar")))); } @Test public void thisProjectDocPath() { assertThat( thisProject.buildDocPath(), hasItem(hasToString(endsWith(".m2/repository/junit/junit/4.12/junit-4.12-sources.jar")))); } @Test public void parseDependencyLine() { var line = "[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"; var path = InferConfig.readDependency(line).get(); assertThat( path, equalTo( Paths.get( "/Users/georgefraser/.m2/repository/org/openjdk/jmh/jmh-generator-annprocess/1.21/jmh-generator-annprocess-1.21.jar"))); } }