From 1d4a8d4d14df3d498bb0ea68feee8ec6a2370856 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 7 Apr 2016 19:04:38 +0200 Subject: SQSCANNER-15 Update Scanner API to 2.6 --- .../java/org/sonarsource/scanner/cli/MainTest.java | 12 +-- .../sonarsource/scanner/cli/RunnerFactoryTest.java | 90 --------------------- .../scanner/cli/ScannerFactoryTest.java | 91 ++++++++++++++++++++++ 3 files changed, 97 insertions(+), 96 deletions(-) delete mode 100644 src/test/java/org/sonarsource/scanner/cli/RunnerFactoryTest.java create mode 100644 src/test/java/org/sonarsource/scanner/cli/ScannerFactoryTest.java (limited to 'src/test') diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java index c0fbd65..4e5da4e 100644 --- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java +++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java @@ -32,7 +32,7 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.sonar.runner.api.EmbeddedRunner; +import org.sonarsource.scanner.api.EmbeddedScanner; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -54,9 +54,9 @@ public class MainTest { @Mock private Properties properties; @Mock - private RunnerFactory runnerFactory; + private ScannerFactory runnerFactory; @Mock - private EmbeddedRunner runner; + private EmbeddedScanner runner; @Mock private Logs logs; @@ -82,7 +82,7 @@ public class MainTest { @Test public void should_stop_on_error() { - EmbeddedRunner runner = mock(EmbeddedRunner.class); + EmbeddedScanner runner = mock(EmbeddedScanner.class); Exception e = new NullPointerException("NPE"); e = new IllegalStateException("Error", e); doThrow(e).when(runner).runAnalysis(any(Properties.class)); @@ -126,7 +126,7 @@ public class MainTest { when(cli.isDebugEnabled()).thenReturn(debugEnabled); when(cli.isDisplayStackTrace()).thenReturn(stackTraceEnabled); - EmbeddedRunner runner = mock(EmbeddedRunner.class); + EmbeddedScanner runner = mock(EmbeddedScanner.class); doThrow(e).when(runner).runAnalysis(any(Properties.class)); when(runnerFactory.create(any(Properties.class))).thenReturn(runner); @@ -140,7 +140,7 @@ public class MainTest { @Test public void should_not_stop_on_error_in_interactive_mode() throws Exception { - EmbeddedRunner runner = mock(EmbeddedRunner.class); + EmbeddedScanner runner = mock(EmbeddedScanner.class); doThrow(new IllegalStateException("Error")).when(runner).runAnalysis(any(Properties.class)); when(runnerFactory.create(any(Properties.class))).thenReturn(runner); when(cli.isInteractive()).thenReturn(true); diff --git a/src/test/java/org/sonarsource/scanner/cli/RunnerFactoryTest.java b/src/test/java/org/sonarsource/scanner/cli/RunnerFactoryTest.java deleted file mode 100644 index 5807952..0000000 --- a/src/test/java/org/sonarsource/scanner/cli/RunnerFactoryTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * SonarQube Scanner - * Copyright (C) 2011-2016 SonarSource SA - * mailto:contact 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.sonarsource.scanner.cli; - -import org.sonar.runner.api.LogOutput.Level; -import org.sonarsource.scanner.cli.Logs; -import org.sonarsource.scanner.cli.RunnerFactory; -import org.sonar.runner.api.LogOutput; -import org.junit.Before; - -import java.util.Properties; - -import static org.mockito.Mockito.verifyNoMoreInteractions; - -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.mock; -import org.junit.Test; -import org.sonar.runner.api.EmbeddedRunner; -import static org.fest.assertions.Assertions.assertThat; - -public class RunnerFactoryTest { - - Properties props = new Properties(); - Logs logs; - - @Before - public void setUp() { - logs = mock(Logs.class); - } - - @Test - public void should_create_embedded_runner() { - props.setProperty("foo", "bar"); - EmbeddedRunner runner = new RunnerFactory(logs).create(props); - - assertThat(runner).isInstanceOf(EmbeddedRunner.class); - assertThat(runner.globalProperties().get("foo")).isEqualTo("bar"); - } - - @Test - public void should_fwd_logs() { - LogOutput logOutput = new RunnerFactory(logs).new DefaultLogOutput(); - - String msg = "test"; - - logOutput.log(msg, Level.DEBUG); - verify(logs).debug(msg); - verifyNoMoreInteractions(logs); - reset(logs); - - logOutput.log(msg, Level.INFO); - verify(logs).info(msg); - verifyNoMoreInteractions(logs); - reset(logs); - - logOutput.log(msg, Level.ERROR); - verify(logs).error(msg); - verifyNoMoreInteractions(logs); - reset(logs); - - logOutput.log(msg, Level.WARN); - verify(logs).info(msg); - verifyNoMoreInteractions(logs); - reset(logs); - - logOutput.log(msg, Level.TRACE); - verify(logs).debug(msg); - verifyNoMoreInteractions(logs); - reset(logs); - } - -} diff --git a/src/test/java/org/sonarsource/scanner/cli/ScannerFactoryTest.java b/src/test/java/org/sonarsource/scanner/cli/ScannerFactoryTest.java new file mode 100644 index 0000000..2e60e81 --- /dev/null +++ b/src/test/java/org/sonarsource/scanner/cli/ScannerFactoryTest.java @@ -0,0 +1,91 @@ +/* + * SonarQube Scanner + * Copyright (C) 2011-2016 SonarSource SA + * mailto:contact 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.sonarsource.scanner.cli; + +import org.sonarsource.scanner.api.EmbeddedScanner; +import org.sonarsource.scanner.api.LogOutput; +import org.sonarsource.scanner.api.LogOutput.Level; +import org.sonarsource.scanner.cli.Logs; +import org.sonarsource.scanner.cli.ScannerFactory; +import org.junit.Before; + +import java.util.Properties; + +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.mock; +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class ScannerFactoryTest { + + Properties props = new Properties(); + Logs logs; + + @Before + public void setUp() { + logs = mock(Logs.class); + } + + @Test + public void should_create_embedded_runner() { + props.setProperty("foo", "bar"); + EmbeddedScanner runner = new ScannerFactory(logs).create(props); + + assertThat(runner).isInstanceOf(EmbeddedScanner.class); + assertThat(runner.globalProperties().get("foo")).isEqualTo("bar"); + } + + @Test + public void should_fwd_logs() { + LogOutput logOutput = new ScannerFactory(logs).new DefaultLogOutput(); + + String msg = "test"; + + logOutput.log(msg, Level.DEBUG); + verify(logs).debug(msg); + verifyNoMoreInteractions(logs); + reset(logs); + + logOutput.log(msg, Level.INFO); + verify(logs).info(msg); + verifyNoMoreInteractions(logs); + reset(logs); + + logOutput.log(msg, Level.ERROR); + verify(logs).error(msg); + verifyNoMoreInteractions(logs); + reset(logs); + + logOutput.log(msg, Level.WARN); + verify(logs).info(msg); + verifyNoMoreInteractions(logs); + reset(logs); + + logOutput.log(msg, Level.TRACE); + verify(logs).debug(msg); + verifyNoMoreInteractions(logs); + reset(logs); + } + +} -- cgit v1.2.3