From 84f0224faf4e45999e793f8d06b66c065dfc6399 Mon Sep 17 00:00:00 2001 From: Klaudio Sinani Date: Wed, 10 Aug 2022 13:37:31 +0200 Subject: 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 --- .../org/sonar/scanner/scan/filesystem/StatusDetectionTest.java | 8 ++++++-- .../org/sonar/scanner/scm/ScmChangedFilesProviderTest.java | 5 ++++- .../test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java | 10 +++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner') 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 files = Collections.singletonList(Paths.get("files")); + Path filePath = Paths.get("files"); + ChangedFile file = new ChangedFile(filePath.toString(), filePath); + Collection 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 files = Collections.singletonList(Paths.get("files")); + Path filePath = Paths.get("files"); + Collection files = Collections.singletonList(new ChangedFile(filePath.toString(), filePath)); scmChangedFiles = new ScmChangedFiles(files); assertThat(scmChangedFiles.isValid()).isTrue(); assertThat(scmChangedFiles.isChanged(Paths.get("files"))).isTrue(); -- cgit v1.2.3