aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2022-03-22 17:11:44 +0100
committersonartech <sonartech@sonarsource.com>2022-03-25 20:02:53 +0000
commit3e2705b20b0073754d5b589755bd921667853feb (patch)
treef70fb07fbe7884be553decb606d9bb6c2a24e89e /sonar-scanner-engine
parent8ecc599d9bcbee170569b2f11d1ea583f1d2354d (diff)
downloadsonarqube-3e2705b20b0073754d5b589755bd921667853feb.tar.gz
sonarqube-3e2705b20b0073754d5b589755bd921667853feb.zip
NO-JIRA fixed creation of temp folder in the unit test to support all Windows' setups
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java20
1 files changed, 13 insertions, 7 deletions
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));
}