aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/sonarsource/scanner/cli/MainTest.java
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-01-13 11:02:45 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2017-01-13 11:02:45 +0100
commita46a865c40ef5eba9a50d317be41a91301167dc2 (patch)
tree412ee00865738d753d00351abab256a7190ee372 /src/test/java/org/sonarsource/scanner/cli/MainTest.java
parent18876beaba96914057a1da9f1cd1c5169721f8dc (diff)
downloadsonar-scanner-cli-a46a865c40ef5eba9a50d317be41a91301167dc2.tar.gz
sonar-scanner-cli-a46a865c40ef5eba9a50d317be41a91301167dc2.zip
Fix quality flaws
Diffstat (limited to 'src/test/java/org/sonarsource/scanner/cli/MainTest.java')
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/MainTest.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
index 3484aef..b410cbd 100644
--- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
@@ -95,7 +95,23 @@ public class MainTest {
}
@Test
- public void show_error() {
+ public void should_exit_on_error() {
+ EmbeddedScanner runner = mock(EmbeddedScanner.class);
+ Exception e = new NullPointerException("NPE");
+ e = new IllegalStateException("Error", e);
+ doThrow(e).when(runner).stop();
+ when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
+
+ Main main = new Main(exit, cli, conf, runnerFactory, logs);
+ main.execute();
+
+ verify(runner).stop();
+ verify(exit).exit(Exit.ERROR);
+ verify(logs).error("Unable to properly stop the scanner", e);
+ }
+
+ @Test
+ public void show_error_with_stacktrace() {
Exception e = createException(false);
testException(e, false);
@@ -109,6 +125,7 @@ public class MainTest {
testException(e, false);
verify(logs).error("Error during SonarQube Scanner execution");
+ verify(logs).error("Caused by: NPE");
verify(logs).error("Re-run SonarQube Scanner using the -X switch to enable full debug logging.");
}
@@ -138,7 +155,7 @@ public class MainTest {
private Exception createException(boolean messageException) {
Exception e;
if (messageException) {
- e = new MessageException("my message");
+ e = new MessageException("my message", new NullPointerException("NPE"));
} else {
e = new IllegalStateException("Error", new NullPointerException("NPE"));
}