diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-06-28 16:42:50 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-06-29 20:03:18 +0000 |
commit | c2a459c2e64af14cdc736d1074829abd8a10bcae (patch) | |
tree | e0b2ecbcd74dbff33d65d14db9de95984fc2c885 /sonar-scanner-engine/src/test | |
parent | a46a61290a9a091a47bf3b76942fa4e59b8b981f (diff) | |
download | sonarqube-c2a459c2e64af14cdc736d1074829abd8a10bcae.tar.gz sonarqube-c2a459c2e64af14cdc736d1074829abd8a10bcae.zip |
SONAR-14890 Link to documentation in Warnings should be relative
Diffstat (limited to 'sonar-scanner-engine/src/test')
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java | 17 | ||||
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java | 23 |
2 files changed, 22 insertions, 18 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java index 21ba297db5e..56a157ac369 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java @@ -27,11 +27,13 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.scm.BlameLine; import org.sonar.api.utils.System2; +import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonar.scanner.notifications.DefaultAnalysisWarnings; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class DefaultBlameOutputTest { @@ -39,22 +41,23 @@ public class DefaultBlameOutputTest { public ExpectedException thrown = ExpectedException.none(); private System2 system2 = mock(System2.class); private DefaultAnalysisWarnings analysisWarnings = new DefaultAnalysisWarnings(system2); + private ScannerWsClient client = mock(ScannerWsClient.class); @Test public void shouldNotFailIfNotSameNumberOfLines() { InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(10).build(); - new DefaultBlameOutput(null, analysisWarnings, singletonList(file)).blameResult(file, singletonList(new BlameLine().revision("1").author("guy"))); + new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client).blameResult(file, singletonList(new BlameLine().revision("1").author("guy"))); } @Test public void addWarningIfFilesMissing() { InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(10).build(); - - new DefaultBlameOutput(null, analysisWarnings, singletonList(file)).finish(true); + when(client.baseUrl()).thenReturn("http://sonarqube/v1"); + new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client).finish(true); assertThat(analysisWarnings.warnings()).extracting(DefaultAnalysisWarnings.Message::getText) .containsOnly("Missing blame information for 1 file. This may lead to some features not working correctly. " + - "Please check the analysis logs and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>."); + "Please check the analysis logs and refer to <a href=\"http://sonarqube/v1/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>."); } @Test @@ -64,7 +67,7 @@ public class DefaultBlameOutputTest { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("It was not expected to blame file " + file); - new DefaultBlameOutput(null, analysisWarnings, singletonList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build())) + new DefaultBlameOutput(null, analysisWarnings, singletonList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build()), client) .blameResult(file, singletonList(new BlameLine().revision("1").author("guy"))); } @@ -75,7 +78,7 @@ public class DefaultBlameOutputTest { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Blame date is null for file " + file + " at line 1"); - new DefaultBlameOutput(null, analysisWarnings, singletonList(file)) + new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client) .blameResult(file, singletonList(new BlameLine().revision("1").author("guy"))); } @@ -86,7 +89,7 @@ public class DefaultBlameOutputTest { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Blame revision is blank for file " + file + " at line 1"); - new DefaultBlameOutput(null, analysisWarnings, singletonList(file)) + new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client) .blameResult(file, singletonList(new BlameLine().date(new Date()).author("guy"))); } 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 3082c716bc9..96226264aa7 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 @@ -44,11 +44,9 @@ import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; -import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryBuilder; -import org.eclipse.jgit.merge.MergeStrategy; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.treewalk.AbstractTreeIterator; @@ -63,6 +61,7 @@ import org.sonar.api.utils.MessageException; import org.sonar.api.utils.System2; import org.sonar.api.utils.log.LogAndArguments; import org.sonar.api.utils.log.LogTester; +import org.sonar.scanner.bootstrap.ScannerWsClient; import static java.util.Collections.emptySet; import static org.assertj.core.api.Assertions.assertThat; @@ -124,6 +123,7 @@ public class GitScmProviderTest { private Path worktree; private Git git; private final AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class); + private final ScannerWsClient client = mock(ScannerWsClient.class); @Before public void before() throws IOException, GitAPIException { @@ -141,7 +141,7 @@ public class GitScmProviderTest { @Test public void returnImplem() { JGitBlameCommand jblameCommand = new JGitBlameCommand(new PathResolver(), analysisWarnings); - GitScmProvider gitScmProvider = new GitScmProvider(jblameCommand, analysisWarnings, gitIgnoreCommand, system2); + GitScmProvider gitScmProvider = new GitScmProvider(jblameCommand, analysisWarnings, gitIgnoreCommand, system2, client); assertThat(gitScmProvider.blameCommand()).isEqualTo(jblameCommand); } @@ -630,7 +630,7 @@ public class GitScmProviderTest { @Test public void branchChangedFiles_should_return_null_on_io_errors_of_repo_builder() { - GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) { + GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) { @Override Repository buildRepo(Path basedir) throws IOException { throw new IOException(); @@ -646,8 +646,9 @@ public class GitScmProviderTest { RefDatabase refDatabase = mock(RefDatabase.class); when(repository.getRefDatabase()).thenReturn(refDatabase); when(refDatabase.findRef(BRANCH_NAME)).thenReturn(null); + when(client.baseUrl()).thenReturn("http://sonarqube.org"); - GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) { + GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) { @Override Repository buildRepo(Path basedir) { return repository; @@ -662,7 +663,7 @@ public class GitScmProviderTest { String warning = refNotFound + ". You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis" - + " and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>."; + + " and refer to <a href=\"http://sonarqube.org/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>."; verify(analysisWarnings).addUnique(warning); } @@ -677,7 +678,7 @@ public class GitScmProviderTest { Git git = mock(Git.class); when(git.diff()).thenReturn(diffCommand); - GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) { + GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) { @Override Git newGit(Repository repo) { return git; @@ -710,7 +711,7 @@ public class GitScmProviderTest { commit(f2); AtomicInteger callCount = new AtomicInteger(0); - GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) { + GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) { @Override AbstractTreeIterator prepareTreeParser(Repository repo, RevCommit commit) throws IOException { if (callCount.getAndIncrement() == 1) { @@ -729,7 +730,7 @@ public class GitScmProviderTest { @Test public void branchChangedLines_returns_null_on_io_errors_of_repo_builder() { - GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) { + GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) { @Override Repository buildRepo(Path basedir) throws IOException { throw new IOException(); @@ -744,7 +745,7 @@ public class GitScmProviderTest { } private GitScmProvider newGitScmProvider() { - return new GitScmProvider(mock(JGitBlameCommand.class), analysisWarnings, gitIgnoreCommand, system2); + return new GitScmProvider(mock(JGitBlameCommand.class), analysisWarnings, gitIgnoreCommand, system2, client); } @Test @@ -889,6 +890,6 @@ public class GitScmProviderTest { } private GitScmProvider newScmProvider() { - return new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2); + return new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client); } } |