aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-09-20 17:11:21 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2017-09-28 09:14:43 +0200
commit5abe7f209af3621d1bd94ef15c9d43e93a056200 (patch)
treebceacae53e61a91e3fab19a5a2de91b44900bc4d /sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java
parent0a201a057cac9263b641614d5491d2061ab3ab80 (diff)
downloadsonarqube-5abe7f209af3621d1bd94ef15c9d43e93a056200.tar.gz
sonarqube-5abe7f209af3621d1bd94ef15c9d43e93a056200.zip
SONAR-9837 Detect files changed in the current branch with SCM
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java21
1 files changed, 19 insertions, 2 deletions
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 6777aaa7333..bf278fee6ce 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
@@ -23,7 +23,9 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
@@ -48,6 +50,9 @@ public class ScmChangedFilesProviderTest {
@Mock
private ScmBranchProvider scmProvider;
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
private Path rootBaseDir = Paths.get("root");
private ScmChangedFilesProvider provider;
@@ -70,6 +75,18 @@ public class ScmChangedFilesProviderTest {
}
@Test
+ public void testFailIfRelativePath() {
+ when(branchConfiguration.branchTarget()).thenReturn("target");
+ when(branchConfiguration.isShortLivingBranch()).thenReturn(true);
+ when(scmConfiguration.provider()).thenReturn(scmProvider);
+ when(scmProvider.branchChangedFiles("target", rootBaseDir)).thenReturn(Collections.singleton(Paths.get("changedFile")));
+
+ exception.expect(IllegalStateException.class);
+ exception.expectMessage("changed file with a relative path");
+ provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
+ }
+
+ @Test
public void testProviderDoesntSupport() {
when(branchConfiguration.branchTarget()).thenReturn("target");
when(branchConfiguration.isShortLivingBranch()).thenReturn(true);
@@ -108,10 +125,10 @@ public class ScmChangedFilesProviderTest {
when(branchConfiguration.branchTarget()).thenReturn("target");
when(branchConfiguration.isShortLivingBranch()).thenReturn(true);
when(scmConfiguration.provider()).thenReturn(scmProvider);
- when(scmProvider.branchChangedFiles("target", rootBaseDir)).thenReturn(Collections.singletonList(Paths.get("changedFile")));
+ when(scmProvider.branchChangedFiles("target", rootBaseDir)).thenReturn(Collections.singleton(Paths.get("changedFile").toAbsolutePath()));
ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
- assertThat(scmChangedFiles.get()).containsOnly(Paths.get("changedFile"));
+ assertThat(scmChangedFiles.get()).containsOnly(Paths.get("changedFile").toAbsolutePath());
verify(scmProvider).branchChangedFiles("target", rootBaseDir);
}