aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2022-08-10 13:37:31 +0200
committersonartech <sonartech@sonarsource.com>2022-10-26 20:03:10 +0000
commit84f0224faf4e45999e793f8d06b66c065dfc6399 (patch)
treebeb055ee1d93aa0966ca01d8cbed088202ae59ef /sonar-scanner-engine/src/test/java/org/sonar/scanner
parent30e6c8d94430d7087f14196032d77e3034262e83 (diff)
downloadsonarqube-84f0224faf4e45999e793f8d06b66c065dfc6399.tar.gz
sonarqube-84f0224faf4e45999e793f8d06b66c065dfc6399.zip
SONAR-13579 Detect files moves in Pull Request scope
SONAR-13579 Get database files from target branch instead of snapshot SONAR-13579 Store old relative file path to `FileAttributes` class
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java8
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java5
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java10
3 files changed, 17 insertions, 6 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java
index 73c736b224b..94629f59b60 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java
@@ -19,9 +19,11 @@
*/
package org.sonar.scanner.scan.filesystem;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.sonar.api.batch.fs.InputFile;
@@ -31,6 +33,7 @@ import org.sonar.scanner.repository.FileData;
import org.sonar.scanner.repository.ProjectRepositories;
import org.sonar.scanner.repository.SingleProjectRepository;
import org.sonar.scanner.scm.ScmChangedFiles;
+import org.sonar.scm.git.ChangedFile;
import static org.assertj.core.api.Assertions.assertThat;
@@ -61,9 +64,10 @@ public class StatusDetectionTest {
@Test
public void detect_status_branches_confirm() {
- ScmChangedFiles changedFiles = new ScmChangedFiles(Collections.singletonList(Paths.get("module", "src", "Foo.java")));
- StatusDetection statusDetection = new StatusDetection(projectRepositories, changedFiles);
+ Path filePath = Paths.get("module", "src", "Foo.java");
+ ScmChangedFiles changedFiles = new ScmChangedFiles(List.of(new ChangedFile(filePath.toString(), filePath)));
+ StatusDetection statusDetection = new StatusDetection(projectRepositories, changedFiles);
assertThat(statusDetection.status("foo", createFile("src/Foo.java"), "XXXXX")).isEqualTo(InputFile.Status.CHANGED);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java
index ec319e1c931..abbc78a3819 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java
@@ -30,6 +30,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.batch.scm.ScmProvider;
import org.sonar.scanner.fs.InputModuleHierarchy;
import org.sonar.scanner.scan.branch.BranchConfiguration;
+import org.sonar.scm.git.ChangedFile;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -130,7 +131,9 @@ public class ScmChangedFilesProviderTest {
when(scmProvider.branchChangedFiles("target", rootBaseDir)).thenReturn(Collections.singleton(Paths.get("changedFile").toAbsolutePath()));
ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, project);
- assertThat(scmChangedFiles.get()).containsOnly(Paths.get("changedFile").toAbsolutePath());
+ Path filePath = Paths.get("changedFile").toAbsolutePath();
+ ChangedFile changedFile = new ChangedFile(filePath.toString(), filePath);
+ assertThat(scmChangedFiles.get()).containsOnly(changedFile);
verify(scmProvider).branchChangedFiles("target", rootBaseDir);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java
index 40d3930713f..856d0573124 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java
@@ -24,6 +24,7 @@ import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import org.junit.Test;
+import org.sonar.scm.git.ChangedFile;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -33,9 +34,11 @@ public class ScmChangedFilesTest {
@Test
public void testGetter() {
- Collection<Path> files = Collections.singletonList(Paths.get("files"));
+ Path filePath = Paths.get("files");
+ ChangedFile file = new ChangedFile(filePath.toString(), filePath);
+ Collection<ChangedFile> files = Collections.singletonList(file);
scmChangedFiles = new ScmChangedFiles(files);
- assertThat(scmChangedFiles.get()).containsOnly(Paths.get("files"));
+ assertThat(scmChangedFiles.get()).containsOnly(file);
}
@Test
@@ -50,7 +53,8 @@ public class ScmChangedFilesTest {
@Test
public void testConfirm() {
- Collection<Path> files = Collections.singletonList(Paths.get("files"));
+ Path filePath = Paths.get("files");
+ Collection<ChangedFile> files = Collections.singletonList(new ChangedFile(filePath.toString(), filePath));
scmChangedFiles = new ScmChangedFiles(files);
assertThat(scmChangedFiles.isValid()).isTrue();
assertThat(scmChangedFiles.isChanged(Paths.get("files"))).isTrue();