aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/CliTest.java11
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/MainTest.java67
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/ShutdownTest.java90
3 files changed, 13 insertions, 155 deletions
diff --git a/src/test/java/org/sonarsource/scanner/cli/CliTest.java b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
index 8e9a4ed..6bac2d0 100644
--- a/src/test/java/org/sonarsource/scanner/cli/CliTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
@@ -20,13 +20,9 @@
package org.sonarsource.scanner.cli;
import org.junit.Test;
-import org.sonarsource.scanner.cli.Cli;
-import org.sonarsource.scanner.cli.Exit;
-import org.sonarsource.scanner.cli.Logs;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
public class CliTest {
Exit exit = mock(Exit.class);
@@ -51,13 +47,6 @@ public class CliTest {
}
@Test
- public void dont_allow_interactive_fork() {
- cli.parse(new String[] {"-i", "-DsonarRunner.mode=fork"});
- cli.verify();
- verify(exit).exit(Exit.SUCCESS);
- }
-
- @Test
public void should_parse_optional_task() {
cli.parse(new String[] {"-D", "foo=bar"});
assertThat(cli.properties().get("sonar.task")).isNull();
diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
index 4e5da4e..06adc9d 100644
--- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
@@ -19,11 +19,7 @@
*/
package org.sonarsource.scanner.cli;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
@@ -46,7 +42,7 @@ import static org.mockito.Mockito.when;
public class MainTest {
@Mock
- private Shutdown shutdown;
+ private Exit exit;
@Mock
private Cli cli;
@Mock
@@ -69,10 +65,10 @@ public class MainTest {
@Test
public void should_execute_runner() {
- Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
+ Main main = new Main(exit, cli, conf, runnerFactory, logs);
main.execute();
- verify(shutdown).exit(Exit.SUCCESS);
+ verify(exit).exit(Exit.SUCCESS);
verify(runnerFactory).create(properties);
verify(runner, times(1)).start();
@@ -88,11 +84,11 @@ public class MainTest {
doThrow(e).when(runner).runAnalysis(any(Properties.class));
when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
- Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
+ Main main = new Main(exit, cli, conf, runnerFactory, logs);
main.execute();
verify(runner).stop();
- verify(shutdown).exit(Exit.ERROR);
+ verify(exit).exit(Exit.ERROR);
verify(logs).error("Caused by: NPE");
}
@@ -130,48 +126,29 @@ public class MainTest {
doThrow(e).when(runner).runAnalysis(any(Properties.class));
when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
- Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
+ Main main = new Main(exit, cli, conf, runnerFactory, logs);
main.execute();
verify(runner).stop();
- verify(shutdown).exit(Exit.ERROR);
+ verify(exit).exit(Exit.ERROR);
return e;
}
@Test
- public void should_not_stop_on_error_in_interactive_mode() throws Exception {
- 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);
-
- Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
- BufferedReader inputReader = mock(BufferedReader.class);
- when(inputReader.readLine()).thenReturn("");
- when(shutdown.shouldExit()).thenReturn(false).thenReturn(true);
- main.setInputReader(inputReader);
- main.execute();
-
- verify(runner, times(2)).runAnalysis(any(Properties.class));
- verify(runner).stop();
- verify(shutdown).exit(Exit.SUCCESS);
- }
-
- @Test
public void should_only_display_version() throws IOException {
Properties p = new Properties();
when(cli.isDisplayVersionOnly()).thenReturn(true);
when(conf.properties()).thenReturn(p);
- Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
+ Main main = new Main(exit, cli, conf, runnerFactory, logs);
main.execute();
- InOrder inOrder = Mockito.inOrder(shutdown, runnerFactory);
+ InOrder inOrder = Mockito.inOrder(exit, runnerFactory);
- inOrder.verify(shutdown, times(1)).exit(Exit.SUCCESS);
+ inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
inOrder.verify(runnerFactory, times(1)).create(p);
- inOrder.verify(shutdown, times(1)).exit(Exit.SUCCESS);
+ inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
}
@Test
@@ -181,7 +158,7 @@ public class MainTest {
when(cli.isDisplayVersionOnly()).thenReturn(true);
when(conf.properties()).thenReturn(p);
- Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
+ Main main = new Main(exit, cli, conf, runnerFactory, logs);
main.execute();
verify(logs).info("SonarQube server 5.5");
}
@@ -209,7 +186,7 @@ public class MainTest {
p.put(propKey, propValue);
when(conf.properties()).thenReturn(p);
- Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
+ Main main = new Main(exit, cli, conf, runnerFactory, logs);
main.execute();
// Logger used for callback should have debug enabled
@@ -222,22 +199,4 @@ public class MainTest {
return propertiesCapture.getValue();
}
- @Test(timeout = 30000)
- public void test_interactive_mode() throws IOException {
- String inputStr = "qwe" + System.lineSeparator() + "qwe" + System.lineSeparator();
- InputStream input = new ByteArrayInputStream(inputStr.getBytes(StandardCharsets.UTF_8));
- System.setIn(input);
- input.close();
-
- when(cli.isInteractive()).thenReturn(true);
- when(cli.isDebugEnabled()).thenReturn(true);
- when(cli.isDisplayStackTrace()).thenReturn(true);
-
- Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
- main.execute();
-
- verify(runner, times(1)).start();
- verify(runner, times(3)).runAnalysis(any(Properties.class));
- verify(runner, times(1)).stop();
- }
}
diff --git a/src/test/java/org/sonarsource/scanner/cli/ShutdownTest.java b/src/test/java/org/sonarsource/scanner/cli/ShutdownTest.java
deleted file mode 100644
index c9a0d52..0000000
--- a/src/test/java/org/sonarsource/scanner/cli/ShutdownTest.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 com.jayway.awaitility.Duration;
-import java.util.concurrent.Callable;
-import java.util.concurrent.TimeUnit;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonarsource.scanner.cli.Exit;
-import org.sonarsource.scanner.cli.Shutdown;
-
-import static com.jayway.awaitility.Awaitility.await;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.verify;
-
-public class ShutdownTest {
- @Mock
- private Exit exit;
- private Shutdown shutdown;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- shutdown = new Shutdown(exit, true);
- }
-
- @Test
- public void testShutdown() {
- shutdown.exit(3);
- verify(exit).exit(3);
- }
-
- @Test(timeout = 60_000)
- public void testWaitReady() throws InterruptedException {
- shutdown = new Shutdown(exit, true, 100_000);
- shutdown.signalReady(false);
- assertThat(shutdown.shouldExit()).isFalse();
-
- final Thread t = new HookCaller();
- t.start();
-
- await().atMost(Duration.TWO_SECONDS).pollDelay(50, TimeUnit.MILLISECONDS).until(new Callable<Boolean>() {
- @Override
- public Boolean call() throws Exception {
- return t.isAlive();
- }
- });
-
- assertThat(shutdown.shouldExit()).isTrue();
-
- shutdown.signalReady(true);
- t.join();
- }
-
- @Test(timeout = 60_000)
- public void testTimeout() throws InterruptedException {
- shutdown = new Shutdown(exit, true, 0);
-
- Thread t = new HookCaller();
- t.start();
- t.join();
- }
-
- private class HookCaller extends Thread {
- @Override
- public void run() {
- shutdown.hook.run();
- }
- }
-}