]> source.dussan.org Git - sonarqube.git/commitdiff
NO-JIRA fixed creation of temp folder in the unit test to support all Windows' setups
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Tue, 22 Mar 2022 16:11:44 +0000 (17:11 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 25 Mar 2022 20:02:53 +0000 (20:02 +0000)
sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java

index 37d22710446b82454f4c77f5efdac15c39278ed8..be64c480015348228f9fa108123a59c4f39f2795 100644 (file)
@@ -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));
   }