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/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.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")));
    }
}

@@ -3020,173 +3020,17 @@
 var 
-path = InferConfig.readDependency(line).get();%0A        assertThat(%0A                path,%0A                equalTo(%0A                        Paths.get(%0A                
+expect =%0A
     
@@ -3153,24 +3153,128 @@
 ss-1.21.jar%22
+;%0A        var path = InferConfig.readDependency(line);%0A        assertThat(path, equalTo(Paths.get(expect
 )));%0A    %7D%0A%7D

Fix test