aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scm/git
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2020-12-14 15:09:06 -0600
committersonartech <sonartech@sonarsource.com>2020-12-15 20:07:25 +0000
commit316c95e86b0215f99d313e56964659cb3a25ece5 (patch)
tree9fcfddce1c0e516159f4d840ed8ba2e6600348fe /sonar-scanner-engine/src/test/java/org/sonar/scm/git
parent2ed2e647067ffa08496c18d3541b213009d57a40 (diff)
downloadsonarqube-316c95e86b0215f99d313e56964659cb3a25ece5.tar.gz
sonarqube-316c95e86b0215f99d313e56964659cb3a25ece5.zip
SONAR-13586 Specify target pull request with the remote name
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scm/git')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java32
1 files changed, 25 insertions, 7 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java
index 7f62b8912fa..e4ddcab275c 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java
@@ -66,7 +66,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.sonar.scm.git.Utils.javaUnzip;
@@ -468,7 +468,7 @@ public class GitScmProviderTest {
assertThat(newScmProvider().branchChangedFiles("master", worktree2))
.containsOnly(worktree2.resolve("file-b1"));
- verifyZeroInteractions(analysisWarnings);
+ verifyNoInteractions(analysisWarnings);
}
@Test
@@ -489,7 +489,7 @@ public class GitScmProviderTest {
assertThat(newScmProvider().branchChangedFiles("master", worktree2))
.containsOnly(worktree2.resolve("file-b1"));
- verifyZeroInteractions(analysisWarnings);
+ verifyNoInteractions(analysisWarnings);
}
@Test
@@ -509,7 +509,7 @@ public class GitScmProviderTest {
assertThat(newScmProvider().branchChangedFiles("local-only", worktree2))
.containsOnly(worktree2.resolve("file-b1"));
- verifyZeroInteractions(analysisWarnings);
+ verifyNoInteractions(analysisWarnings);
}
@Test
@@ -527,11 +527,29 @@ public class GitScmProviderTest {
assertThat(newScmProvider().branchChangedFiles("master", worktree2))
.containsOnly(worktree2.resolve("file-b1"));
- verifyZeroInteractions(analysisWarnings);
+ verifyNoInteractions(analysisWarnings);
}
@Test
+ public void branchChangedFiles_finds_branch_in_specific_origin() throws IOException, GitAPIException {
+ git.branchCreate().setName("b1").call();
+ git.checkout().setName("b1").call();
+ createAndCommitFile("file-b1");
+
+ Path worktree2 = temp.newFolder().toPath();
+ Git.cloneRepository()
+ .setURI(worktree.toString())
+ .setRemote("upstream")
+ .setDirectory(worktree2.toFile())
+ .call();
+
+ assertThat(newScmProvider().branchChangedFiles("upstream/master", worktree2))
+ .containsOnly(worktree2.resolve("file-b1"));
+ verifyNoInteractions(analysisWarnings);
+ }
+
+ @Test
public void branchChangedFiles_should_return_null_when_branch_nonexistent() {
assertThat(newScmProvider().branchChangedFiles("nonexistent", worktree)).isNull();
}
@@ -559,7 +577,7 @@ public class GitScmProviderTest {
}
};
assertThat(provider.branchChangedFiles("branch", worktree)).isNull();
- verifyZeroInteractions(analysisWarnings);
+ verifyNoInteractions(analysisWarnings);
}
@Test
@@ -577,7 +595,7 @@ public class GitScmProviderTest {
};
assertThat(provider.branchChangedFiles("branch", worktree)).isNull();
- String warning = "Could not find ref 'branch' in refs/heads, refs/remotes/upstream or refs/remotes/origin."
+ String warning = "Could not find ref 'branch' in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin."
+ " You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis.";
verify(analysisWarnings).addUnique(warning);
}