diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-06-09 16:26:56 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-06-17 20:03:08 +0000 |
commit | 2754feca4e5fa8fdd804c827783250f48676296c (patch) | |
tree | 1ed9522bbc9eff9444fae6bf0a951d976da2b859 /sonar-scanner-engine/src/test | |
parent | 97f2c01fdd4ae863134d4aa1bf32b7dcd512b10c (diff) | |
download | sonarqube-2754feca4e5fa8fdd804c827783250f48676296c.tar.gz sonarqube-2754feca4e5fa8fdd804c827783250f48676296c.zip |
SONAR-14925 Remove code deprecated before 7.0 in the Plugin API
Diffstat (limited to 'sonar-scanner-engine/src/test')
13 files changed, 63 insertions, 230 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java index e60676ce65f..364567e4633 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.bootstrap; import java.util.Arrays; import org.apache.commons.lang.ClassUtils; import org.junit.Test; -import org.sonar.api.ExtensionProvider; import org.sonar.api.Plugin; import org.sonar.api.SonarRuntime; import org.sonar.api.batch.ScannerSide; @@ -56,41 +55,9 @@ public class ExtensionInstallerTest { assertThat(container.getComponentByType(Bar.class)).isNull(); } - @Test - public void should_execute_extension_provider() { - when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); - when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooProvider(), new BarProvider())); - ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, settings.asConfig()); - - installer.install(container, new FooMatcher()); - - assertThat(container.getComponentByType(Foo.class)).isNotNull(); - assertThat(container.getComponentByType(Bar.class)).isNull(); - } - - @Test - public void should_provide_list_of_extensions() { - when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); - when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooBarProvider())); - ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, settings.asConfig()); - - installer.install(container, new TrueMatcher()); - - assertThat(container.getComponentByType(Foo.class)).isNotNull(); - assertThat(container.getComponentByType(Bar.class)).isNotNull(); - } - private static class FooMatcher implements ExtensionMatcher { public boolean accept(Object extension) { - return extension.equals(Foo.class) || ClassUtils.isAssignable(Foo.class, extension.getClass()) || ClassUtils.isAssignable(FooProvider.class, extension.getClass()); - } - } - - private static class TrueMatcher implements ExtensionMatcher { - public boolean accept(Object extension) { - return true; + return extension.equals(Foo.class) || ClassUtils.isAssignable(Foo.class, extension.getClass()); } } @@ -103,29 +70,4 @@ public class ExtensionInstallerTest { public static class Bar { } - - @ScannerSide - public static class FooProvider extends ExtensionProvider { - @Override - public Object provide() { - return new Foo(); - } - } - - @ScannerSide - public static class BarProvider extends ExtensionProvider { - @Override - public Object provide() { - return new Bar(); - } - } - - @ScannerSide - public static class FooBarProvider extends ExtensionProvider { - @Override - public Object provide() { - return Arrays.asList(new Foo(), new Bar()); - } - } - } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java deleted file mode 100644 index fbc809e8960..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.bootstrap; - -import java.util.Arrays; -import java.util.List; -import org.junit.Test; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.Metrics; - -import static org.assertj.core.api.Assertions.assertThat; - -public class MetricProviderTest { - @Test - public void should_provide_at_least_core_metrics() { - MetricProvider provider = new MetricProvider(); - List<Metric> metrics = provider.provide(); - - assertThat(metrics).hasSize(CoreMetrics.getMetrics().size()); - assertThat(metrics).extracting("key").contains("ncloc"); - } - - @Test - public void should_provide_plugin_metrics() { - Metrics factory = () -> Arrays.asList(new Metric.Builder("custom", "Custom", Metric.ValueType.FLOAT).create()); - MetricProvider provider = new MetricProvider(new Metrics[] {factory}); - List<Metric> metrics = provider.provide(); - - assertThat(metrics.size()).isEqualTo(1 + CoreMetrics.getMetrics().size()); - assertThat(metrics).extracting("key").contains("custom"); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/perspectives/PerspectiveBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/perspectives/PerspectiveBuilderTest.java deleted file mode 100644 index ce4cf0529c9..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/perspectives/PerspectiveBuilderTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.deprecated.perspectives; - -import org.junit.Test; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.component.Perspective; - -import static org.assertj.core.api.Assertions.assertThat; - -public class PerspectiveBuilderTest { - - @Test - public void testGetPerspectiveClass() { - PerspectiveBuilder<FakePerspective> builder = new PerspectiveBuilder<FakePerspective>(FakePerspective.class) { - @Override - public FakePerspective loadPerspective(Class<FakePerspective> perspectiveClass, InputComponent component) { - return null; - } - }; - - assertThat(builder.getPerspectiveClass()).isEqualTo(FakePerspective.class); - } - - interface FakePerspective extends Perspective { - - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/test/DefaultTestCaseTest.java index 34f2d0d9e9d..27d4884a227 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/test/DefaultTestCaseTest.java @@ -17,20 +17,28 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.scanner.analysis; +package org.sonar.scanner.deprecated.test; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -public class DefaultAnalysisModeTest { +public class DefaultTestCaseTest { + private final DefaultTestCase testCase = new DefaultTestCase(); @Test - public void test() { - DefaultAnalysisMode mode = new DefaultAnalysisMode(); - assertThat(mode.isPublish()).isTrue(); - assertThat(mode.isIssues()).isFalse(); - assertThat(mode.isPreview()).isFalse(); - } + public void getters_after_setters() { + testCase + .setMessage("message") + .setName("name") + .setType("type") + .setDurationInMs(1234L) + .setStatus(DefaultTestCase.Status.FAILURE); + assertThat(testCase.status()).isEqualTo(DefaultTestCase.Status.FAILURE); + assertThat(testCase.name()).isEqualTo("name"); + assertThat(testCase.type()).isEqualTo("type"); + assertThat(testCase.durationInMs()).isEqualTo(1234L); + assertThat(testCase.message()).isEqualTo("message"); + } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java index dc3ee60b081..8afe338e6e3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java @@ -27,19 +27,18 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.test.MutableTestCase; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.api.utils.MessageException; -import org.sonar.scanner.deprecated.test.TestPlanBuilder; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.internal.SensorContextTester; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.deprecated.test.DefaultTestCase; +import org.sonar.scanner.deprecated.test.DefaultTestPlan; +import org.sonar.scanner.deprecated.test.TestPlanBuilder; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -53,7 +52,7 @@ public class GenericTestExecutionReportParserTest { private DefaultInputFile fileWithBranches; private DefaultInputFile emptyFile; private SensorContextTester context; - private MutableTestPlan testPlan; + private DefaultTestPlan testPlan; @Before public void before() { @@ -62,10 +61,10 @@ public class GenericTestExecutionReportParserTest { emptyFile = setupFile("src/main/java/com/example/EmptyClass.java"); testPlanBuilder = mock(TestPlanBuilder.class); - MutableTestCase testCase = mockMutableTestCase(); + DefaultTestCase testCase = mockMutableTestCase(); testPlan = mockMutableTestPlan(testCase); - when(testPlanBuilder.loadPerspective(eq(MutableTestPlan.class), any(InputFile.class))).thenReturn(testPlan); + when(testPlanBuilder.getTestPlan(any(InputFile.class))).thenReturn(testPlan); } @Test @@ -159,18 +158,17 @@ public class GenericTestExecutionReportParserTest { .build(); } - private MutableTestPlan mockMutableTestPlan(MutableTestCase testCase) { - MutableTestPlan testPlan = mock(MutableTestPlan.class); + private DefaultTestPlan mockMutableTestPlan(DefaultTestCase testCase) { + DefaultTestPlan testPlan = mock(DefaultTestPlan.class); when(testPlan.addTestCase(anyString())).thenReturn(testCase); return testPlan; } - private MutableTestCase mockMutableTestCase() { - MutableTestCase testCase = mock(MutableTestCase.class); + private DefaultTestCase mockMutableTestCase() { + DefaultTestCase testCase = mock(DefaultTestCase.class); when(testCase.setDurationInMs(anyLong())).thenReturn(testCase); - when(testCase.setStatus(any(org.sonar.api.test.TestCase.Status.class))).thenReturn(testCase); + when(testCase.setStatus(any(DefaultTestCase.Status.class))).thenReturn(testCase); when(testCase.setMessage(anyString())).thenReturn(testCase); - when(testCase.setStackTrace(anyString())).thenReturn(testCase); when(testCase.setType(anyString())).thenReturn(testCase); return testCase; } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java index 076a5309626..84eeccad942 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java @@ -60,7 +60,7 @@ public class HighlightingMediumTest { File xooFile = new File(srcDir, "sample.xoo"); File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting"); FileUtils.write(xooFile, "Sample xoo\ncontent plop"); - FileUtils.write(xoohighlightingFile, "0:10:s\n11:18:k"); + FileUtils.write(xoohighlightingFile, "1:0:2:0:s\n2:0:2:8:k"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() @@ -115,7 +115,7 @@ public class HighlightingMediumTest { File xooFile = new File(srcDir, "sample.xoo"); File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting"); FileUtils.write(xooFile, "Sample xoo\ncontent plop"); - FileUtils.write(xoohighlightingFile, "0:10:s\n18:18:k"); + FileUtils.write(xoohighlightingFile, "1:0:1:10:s\n2:18:2:18:k"); exception.expect(IllegalStateException.class); exception.expectMessage("Error processing line 2"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java index f9d333716fd..085b1b3b5e6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java @@ -55,7 +55,7 @@ public class SymbolMediumTest { File xooSymbolFile = new File(srcDir, "sample.xoo.symbol"); FileUtils.write(xooFile, "Sample xoo\ncontent\nanother xoo"); // Highlight xoo symbol - FileUtils.write(xooSymbolFile, "7:10,27"); + FileUtils.write(xooSymbolFile, "1:7:1:10,3:8:3:11"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() @@ -84,7 +84,7 @@ public class SymbolMediumTest { File xooSymbolFile = new File(srcDir, "sample.xoo.symbol"); FileUtils.write(xooFile, "Sample xoo\ncontent\nanother xoo\nyet another"); // Highlight xoo symbol - FileUtils.write(xooSymbolFile, "7:10,27:32"); + FileUtils.write(xooSymbolFile, "1:7:1:10,3:8:4:1"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java index 246daa29d8c..09c043d88d3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java @@ -19,12 +19,12 @@ */ package org.sonar.scanner.platform; -import org.sonar.api.SonarEdition; import org.junit.Test; import org.sonar.api.CoreProperties; +import org.sonar.api.SonarEdition; import org.sonar.api.SonarQubeSide; -import org.sonar.api.config.internal.Settings; import org.sonar.api.config.internal.MapSettings; +import org.sonar.api.config.internal.Settings; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.Version; import org.sonar.scanner.bootstrap.DefaultScannerWsClient; @@ -49,12 +49,10 @@ public class DefaultServerTest { assertThat(metadata.getId()).isEqualTo("123"); assertThat(metadata.getVersion()).isEqualTo("2.2"); assertThat(metadata.getStartedAt()).isNotNull(); - assertThat(metadata.getURL()).isEqualTo("http://foo.com"); + assertThat(metadata.getPublicRootUrl()).isEqualTo("http://foo.com"); assertThat(metadata.getPermanentServerId()).isEqualTo("123"); - assertThat(metadata.getRootDir()).isNull(); assertThat(metadata.getContextPath()).isNull(); - assertThat(metadata.isDev()).isFalse(); assertThat(metadata.isSecured()).isFalse(); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java index ebce30b77dd..47ca50c01d3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java @@ -21,30 +21,26 @@ package org.sonar.scanner.postjob; import org.junit.Before; import org.junit.Test; -import org.sonar.api.batch.AnalysisMode; +import org.sonar.api.config.Configuration; import org.sonar.api.config.internal.MapSettings; -import static org.mockito.Mockito.mock; +import static org.assertj.core.api.Assertions.assertThat; public class DefaultPostJobContextTest { private DefaultPostJobContext context; private MapSettings settings; + private Configuration configuration; @Before public void setUp() { settings = new MapSettings(); - AnalysisMode analysisMode = mock(AnalysisMode.class); - context = new DefaultPostJobContext(settings.asConfig(), analysisMode); + configuration = settings.asConfig(); + context = new DefaultPostJobContext(configuration); } - @Test(expected=UnsupportedOperationException.class) - public void testIssues() { - context.issues(); - } - - @Test(expected=UnsupportedOperationException.class) - public void testResolvedIssues() { - context.resolvedIssues(); + @Test + public void getConfig() { + assertThat(context.config()).isEqualTo(configuration); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java index ac730ff28da..9769c914d97 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.ScannerSide; import org.sonar.api.server.ServerSide; -import org.sonar.api.task.TaskExtension; import org.sonar.scanner.bootstrap.ExtensionMatcher; import static org.assertj.core.api.Assertions.assertThat; @@ -41,8 +40,6 @@ public class ProjectScanContainerTest { assertThat(filter.accept(MyProjectExtension.class)).isFalse(); assertThat(filter.accept(new MyServerExtension())).isFalse(); assertThat(filter.accept(MyServerExtension.class)).isFalse(); - assertThat(filter.accept(new MyTaskExtension())).isFalse(); - assertThat(filter.accept(MyTaskExtension.class)).isFalse(); } @ScannerSide @@ -61,8 +58,4 @@ public class ProjectScanContainerTest { static class MyServerExtension { } - - static class MyTaskExtension implements TaskExtension { - - } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java index 9e87bf87ae9..70dcfe524ee 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java @@ -31,7 +31,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Answers; import org.sonar.api.CoreProperties; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.scm.ScmProvider; import org.sonar.api.config.Configuration; import org.sonar.api.notifications.AnalysisWarnings; @@ -45,7 +44,7 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyString; 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.mockito.Mockito.withSettings; import static org.sonar.scanner.scm.ScmConfiguration.MESSAGE_SCM_EXCLUSIONS_IS_DISABLED_BY_CONFIGURATION; @@ -55,7 +54,6 @@ import static org.sonar.scanner.scm.ScmConfiguration.MESSAGE_SCM_STEP_IS_DISABLE public class ScmConfigurationTest { private final InputModuleHierarchy inputModuleHierarchy = mock(InputModuleHierarchy.class, withSettings().defaultAnswer(Answers.RETURNS_MOCKS)); - private final AnalysisMode analysisMode = mock(AnalysisMode.class); private final AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class); private final Configuration settings = mock(Configuration.class); @@ -71,10 +69,9 @@ public class ScmConfigurationTest { public ExpectedException thrown = ExpectedException.none(); public ScmConfigurationTest() { - when(analysisMode.isIssues()).thenReturn(false); when(scmProvider.key()).thenReturn(scmProviderKey); - underTest = new ScmConfiguration(inputModuleHierarchy, analysisMode, settings, analysisWarnings, scmProvider); + underTest = new ScmConfiguration(inputModuleHierarchy, settings, analysisWarnings, scmProvider); } @Test @@ -84,7 +81,14 @@ public class ScmConfigurationTest { underTest.start(); assertThat(underTest.provider()).isNotNull(); - verifyZeroInteractions(analysisWarnings); + verifyNoInteractions(analysisWarnings); + } + + @Test + public void no_provider_if_no_provider_is_available() { + ScmConfiguration underTest = new ScmConfiguration(inputModuleHierarchy, settings, analysisWarnings); + assertThat(underTest.provider()).isNull(); + verifyNoInteractions(analysisWarnings); } @Test @@ -135,23 +139,12 @@ public class ScmConfigurationTest { } @Test - public void return_early_from_start_in_issues_mode() { - // return early = doesn't reach the logging when disabled - when(settings.getBoolean(CoreProperties.SCM_DISABLED_KEY)).thenReturn(Optional.of(true)); - when(analysisMode.isIssues()).thenReturn(true); - - underTest.start(); - - assertThat(logTester.logs()).isEmpty(); - } - - @Test public void fail_when_multiple_scm_providers_claim_support() { when(scmProvider.supports(any())).thenReturn(true); when(scmProvider.key()).thenReturn("key1", "key2"); ScmProvider[] providers = {scmProvider, scmProvider}; - ScmConfiguration underTest = new ScmConfiguration(inputModuleHierarchy, analysisMode, settings, analysisWarnings, providers); + ScmConfiguration underTest = new ScmConfiguration(inputModuleHierarchy, settings, analysisWarnings, providers); thrown.expect(MessageException.class); thrown.expectMessage( diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java index a9c2ebb510f..96b1b58dccb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java @@ -213,7 +213,7 @@ public class DefaultSensorStorageTest { DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php") .setContents("// comment").build(); - DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(0, 1, TypeOfText.KEYWORD); + DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(1, 0, 1, 1, TypeOfText.KEYWORD); underTest.store(highlighting); assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.scannerId())).isTrue(); @@ -226,7 +226,7 @@ public class DefaultSensorStorageTest { .setStatus(InputFile.Status.SAME).build(); when(branchConfiguration.isPullRequest()).thenReturn(true); - DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(0, 1, TypeOfText.KEYWORD); + DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(1, 0, 1, 1, TypeOfText.KEYWORD); underTest.store(highlighting); assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.scannerId())).isFalse(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java index 08c1e3d97d7..f0054ef1546 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java @@ -25,14 +25,14 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.rule.internal.NewActiveRule; -import org.sonar.api.config.internal.MapSettings; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.api.batch.rule.ActiveRules; +import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; +import org.sonar.api.batch.rule.internal.NewActiveRule; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.rule.RuleKey; -import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import static org.assertj.core.api.Assertions.assertThat; @@ -123,8 +123,8 @@ public class ModuleSensorOptimizerTest { @Test public void should_optimize_on_settings() { - DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor() - .requireProperty("sonar.foo.reportPath"); + DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor(); + descriptor.onlyWhenConfiguration(c -> c.hasKey("sonar.foo.reportPath")); assertThat(optimizer.shouldExecute(descriptor)).isFalse(); settings.setProperty("sonar.foo.reportPath", "foo"); |