// Path: sonar-plugin-server/src/test/java/jetbrains/buildserver/sonarplugin/DataProviders.java
// public class DataProviders {
//     @DataProvider
//     private static Object[][] getFileSystemAndRoot() {
//         return new Object[][]{
//                 {Jimfs.newFileSystem(Configuration.windows()), "C:\\"},
//                 {Jimfs.newFileSystem(Configuration.unix()), "/"}
// //                , {Jimfs.newFileSystem(Configuration.osX()), "/"}
//         };
//     }
// }
// 
// Path: sonar-plugin-agent/src/test/java/jetbrains/buildserver/sonarplugin/TestTools.java
// public final class TestTools {
//     public static Path createTempDirectory() throws IOException {
//         return Files.createTempDirectory("keystoreTemp");
//     }
// 
//     public static File writeTo(String prefix, String content) {
//         return writeTo(prefix, content, ".tmp", null);
//     }
// 
//     public static File writeTo(String prefix, String content, String suffix) {
//         return writeTo(prefix, content, suffix, null);
//     }
// 
//     public static File writeTo(String prefix, String content, String suffix, File baseFolder) {
//         File tempFile = null;
//         try {
//             tempFile = File.createTempFile(prefix, suffix, baseFolder);
//             FileWriter fw = new FileWriter(tempFile);
//             fw.write(content);
//             fw.flush();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         return tempFile;
//     }
// 
// }


import jetbrains.buildServer.tools.GetPackageVersionResult;
import jetbrains.buildServer.tools.ToolException;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import jetbrains.buildserver.sonarplugin.DataProviders;
import jetbrains.buildserver.sonarplugin.TestTools;
import org.jetbrains.annotations.NotNull;
import org.jmock.Mockery;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.BDDAssertions.then;

        GetPackageVersionResult res = myToolProvider.parseVersion(zip, "1.2.3");
        then(res.getToolVersion()).describedAs("Should be correct plugin but was '" + res.getDetails() + "'").isNotNull();
        then(res.getToolVersion().getVersion()).isEqualTo("1.2.3");
    }

    public void testParseVersionIncorrect(@NotNull final FileSystem jimfs, @NotNull final String root) throws Exception {
        Path zip = prepareIncorrectPlugin(jimfs, root, "some", "path");

        GetPackageVersionResult res = myToolProvider.parseVersion(zip, "1.2.3");
        then(res.getToolVersion()).isNull();
        then(res.getDetails()).doesNotContain(SimpleZipToolProviderSQMSBuild.BIN).contains(SimpleZipToolProviderSQMSBuild.SONAR_QUBE_SCANNER_MSBUILD_EXE);

        zip = TestTools.prepareZip(getPluginPath(jimfs, root, "some", "path"), CORRECT_PLUGIN_NAME, zfs -> {
            Files.createDirectory(zfs.getPath(SimpleZipToolProviderSQMSBuild.BIN));
        });

        res = myToolProvider.parseVersion(zip, "1.2.3");
        then(res.getToolVersion()).isNull();
        then(res.getDetails()).doesNotContain(SimpleZipToolProviderSQMSBuild.BIN).contains(SimpleZipToolProviderSQMSBuild.SONAR_QUBE_SCANNER_MSBUILD_EXE);
    }

    public void testLayoutContents(@NotNull final FileSystem jimfs, @NotNull final String root) throws Exception {
        Path zip = prepareCorrectPlugin(jimfs, root, "some", "path");

        Path target = jimfs.getPath(root, "target");
        myToolProvider.layoutContents(zip, target);

        Path xml = target.resolve(SimpleZipToolProviderSQMSBuild.TEAMCITY_PLUGIN_XML);
        then(Files.exists(xml)).describedAs(SimpleZipToolProviderSQMSBuild.TEAMCITY_PLUGIN_XML + " should have been created").isTrue();
// Path: sonar-plugin-server/src/test/java/jetbrains/buildserver/sonarplugin/DataProviders.java
// public class DataProviders {
//     @DataProvider
//     private static Object[][] getFileSystemAndRoot() {
//         return new Object[][]{
//                 {Jimfs.newFileSystem(Configuration.windows()), "C:\\"},
//                 {Jimfs.newFileSystem(Configuration.unix()), "/"}
// //                , {Jimfs.newFileSystem(Configuration.osX()), "/"}
//         };
//     }
// }
// 
// Path: sonar-plugin-agent/src/test/java/jetbrains/buildserver/sonarplugin/TestTools.java
// public final class TestTools {
//     public static Path createTempDirectory() throws IOException {
//         return Files.createTempDirectory("keystoreTemp");
//     }
// 
//     public static File writeTo(String prefix, String content) {
//         return writeTo(prefix, content, ".tmp", null);
//     }
// 
//     public static File writeTo(String prefix, String content, String suffix) {
//         return writeTo(prefix, content, suffix, null);
//     }
// 
//     public static File writeTo(String prefix, String content, String suffix, File baseFolder) {
//         File tempFile = null;
//         try {
//             tempFile = File.createTempFile(prefix, suffix, baseFolder);
//             FileWriter fw = new FileWriter(tempFile);
//             fw.write(content);
//             fw.flush();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         return tempFile;
//     }
// 
// }


// Path: sonar-plugin-server/src/test/java/jetbrains/buildserver/sonarplugin/msbuild/tool/SimpleZipToolProviderSQMSBuildTest.java
import jetbrains.buildServer.tools.GetPackageVersionResult;
import jetbrains.buildServer.tools.ToolException;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import jetbrains.buildserver.sonarplugin.DataProviders;
import jetbrains.buildserver.sonarplugin.TestTools;
import org.jetbrains.annotations.NotNull;
import org.jmock.Mockery;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.BDDAssertions.then;


        GetPackageVersionResult res = myToolProvider.parseVersion(zip, "1.2.3");
        then(res.getToolVersion()).describedAs("Should be correct plugin but was '" + res.getDetails() + "'").isNotNull();
        then(res.getToolVersion().getVersion()).isEqualTo("1.2.3");
    }

    public void testParseVersionIncorrect(@NotNull final FileSystem jimfs, @NotNull final String root) throws Exception {
        Path zip = prepareIncorrectPlugin(jimfs, root, "some", "path");

        GetPackageVersionResult res = myToolProvider.parseVersion(zip, "1.2.3");
        then(res.getToolVersion()).isNull();
        then(res.getDetails()).doesNotContain(SimpleZipToolProviderSQMSBuild.BIN).contains(SimpleZipToolProviderSQMSBuild.SONAR_QUBE_SCANNER_MSBUILD_EXE);

        zip = TestTools.prepareZip(getPluginPath(jimfs, root, "some", "path"), CORRECT_PLUGIN_NAME, zfs -> {
            Files.createDirectory(zfs.getPath(SimpleZipToolProviderSQMSBuild.BIN));
        });

        res = myToolProvider.parseVersion(zip, "1.2.3");
        then(res.getToolVersion()).isNull();
        then(res.getDetails()).doesNotContain(SimpleZipToolProviderSQMSBuild.BIN).contains(SimpleZipToolProviderSQMSBuild.SONAR_QUBE_SCANNER_MSBUILD_EXE);
    }

    public void testLayoutContents(@NotNull final FileSystem jimfs, @NotNull final String root) throws Exception {
        Path zip = prepareCorrectPlugin(jimfs, root, "some", "path");

        Path target = jimfs.getPath(root, "target");
        myToolProvider.layoutContents(zip, target);

        Path xml = target.resolve(SimpleZipToolProviderSQMSBuild.TEAMCITY_PLUGIN_XML);
        then(Files.exists(xml)).describedAs(SimpleZipToolProviderSQMSBuild.TEAMCITY_PLUGIN_XML + " should have been created").isTrue();
        List<String> lines = Files.readAllLines(xml);