From: Lukasz Jarocki Date: Tue, 22 Mar 2022 16:11:44 +0000 (+0100) Subject: NO-JIRA fixed creation of temp folder in the unit test to support all Windows' setups X-Git-Tag: 9.4.0.54424~53 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3e2705b20b0073754d5b589755bd921667853feb;p=sonarqube.git NO-JIRA fixed creation of temp folder in the unit test to support all Windows' setups --- diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java index 37d22710446..be64c480015 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java @@ -22,6 +22,7 @@ package org.sonar.scm.git; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.LinkOption; import java.nio.file.Path; import java.util.Arrays; import java.util.Collections; @@ -72,7 +73,7 @@ public class JGitBlameCommandTest { @Test public void testBlame() throws IOException { - File projectDir = temp.newFolder(); + File projectDir = createNewTempFolder(); javaUnzip("dummy-git.zip", projectDir); JGitBlameCommand jGitBlameCommand = newJGitBlameCommand(); @@ -114,7 +115,7 @@ public class JGitBlameCommandTest { @Test public void properFailureIfNotAGitProject() throws IOException { - File projectDir = temp.newFolder(); + File projectDir = createNewTempFolder(); javaUnzip("dummy-git.zip", projectDir); JGitBlameCommand jGitBlameCommand = newJGitBlameCommand(); @@ -139,7 +140,7 @@ public class JGitBlameCommandTest { @Test public void testBlameOnNestedModule() throws IOException { - File projectDir = temp.newFolder(); + File projectDir = createNewTempFolder(); javaUnzip("dummy-git-nested.zip", projectDir); JGitBlameCommand jGitBlameCommand = newJGitBlameCommand(); @@ -191,7 +192,7 @@ public class JGitBlameCommandTest { @Test public void dontFailOnModifiedFile() throws IOException { - File projectDir = temp.newFolder(); + File projectDir = createNewTempFolder(); javaUnzip("dummy-git.zip", projectDir); JGitBlameCommand jGitBlameCommand = newJGitBlameCommand(); @@ -214,7 +215,7 @@ public class JGitBlameCommandTest { @Test public void dontFailOnNewFile() throws IOException { - File projectDir = temp.newFolder(); + File projectDir = createNewTempFolder(); javaUnzip("dummy-git.zip", projectDir); JGitBlameCommand jGitBlameCommand = newJGitBlameCommand(); @@ -271,7 +272,7 @@ public class JGitBlameCommandTest { @Test public void return_early_when_shallow_clone_detected() throws IOException { - File projectDir = temp.newFolder(); + File projectDir = createNewTempFolder(); javaUnzip("shallow-git.zip", projectDir); File baseDir = new File(projectDir, "shallow-git"); @@ -297,7 +298,7 @@ public class JGitBlameCommandTest { @Test public void return_early_when_clone_with_reference_detected() throws IOException { - File projectDir = temp.newFolder(); + File projectDir = createNewTempFolder(); javaUnzip("dummy-git-reference-clone.zip", projectDir); Path baseDir = projectDir.toPath().resolve("dummy-git2"); @@ -324,6 +325,11 @@ public class JGitBlameCommandTest { verifyZeroInteractions(analysisWarnings); } + private File createNewTempFolder() throws IOException { + //This is needed for Windows, otherwise the created File point to invalid (shortened by Windows) temp folder path + return temp.newFolder().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS).toFile(); + } + private JGitBlameCommand newJGitBlameCommand() { return new JGitBlameCommand(new PathResolver(), mock(AnalysisWarnings.class)); }