aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/sonarsource/scanner/cli/CliTest.java
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2024-04-30 14:59:03 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2024-05-03 13:07:43 +0200
commitb04cd6ba08a93a88553c1dfceaa725ced1ba381c (patch)
tree762512e8d5a70bd6981706c5d779a982c57ad75a /src/test/java/org/sonarsource/scanner/cli/CliTest.java
parentfd82dd7b5a54d2042da17baff7088329123797ac (diff)
downloadsonar-scanner-cli-b04cd6ba08a93a88553c1dfceaa725ced1ba381c.tar.gz
sonar-scanner-cli-b04cd6ba08a93a88553c1dfceaa725ced1ba381c.zip
SCANCLI-145 Update to the scanner library 3.0
Diffstat (limited to 'src/test/java/org/sonarsource/scanner/cli/CliTest.java')
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/CliTest.java56
1 files changed, 25 insertions, 31 deletions
diff --git a/src/test/java/org/sonarsource/scanner/cli/CliTest.java b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
index 961f7d1..ce5b140 100644
--- a/src/test/java/org/sonarsource/scanner/cli/CliTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
@@ -22,11 +22,13 @@ package org.sonarsource.scanner.cli;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatNoException;
+import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
public class CliTest {
- private Exit exit = mock(Exit.class);
+ private final Exit exit = mock(Exit.class);
private Logs logs = new Logs(System.out, System.err);
private Cli cli = new Cli(exit, logs);
@@ -41,17 +43,18 @@ public class CliTest {
@Test
public void should_extract_properties() {
- cli.parse(new String[] {"-D", "foo=bar", "--define", "hello=world", "-Dboolean"});
- assertThat(cli.properties().get("foo")).isEqualTo("bar");
- assertThat(cli.properties().get("hello")).isEqualTo("world");
- assertThat(cli.properties().get("boolean")).isEqualTo("true");
+ cli.parse(new String[]{"-D", "foo=bar", "--define", "hello=world", "-Dboolean"});
+ assertThat(cli.properties()).contains(
+ entry("foo", "bar"),
+ entry("hello", "world"),
+ entry("boolean", "true"));
}
@Test
public void should_warn_on_duplicate_properties() {
logs = mock(Logs.class);
cli = new Cli(exit, logs);
- cli.parse(new String[] {"-D", "foo=bar", "--define", "foo=baz"});
+ cli.parse(new String[]{"-D", "foo=bar", "--define", "foo=baz"});
verify(logs).warn("Property 'foo' with value 'bar' is overridden with value 'baz'");
}
@@ -59,75 +62,66 @@ public class CliTest {
public void should_fail_on_missing_prop() {
logs = mock(Logs.class);
cli = new Cli(exit, logs);
- cli.parse(new String[] {"-D"});
+ cli.parse(new String[]{"-D"});
verify(logs).error("Missing argument for option -D/--define");
verify(exit).exit(Exit.INTERNAL_ERROR);
}
@Test
public void should_not_fail_with_errors_option() {
- cli.parse(new String[] {"-e"});
- }
-
- @Test
- public void should_parse_optional_task() {
- cli.parse(new String[] {"-D", "foo=bar"});
- assertThat(cli.properties().get("sonar.task")).isNull();
-
- cli.parse(new String[] {"views", "-D", "foo=bar"});
- assertThat(cli.properties().get("sonar.task")).isEqualTo("views");
+ assertThatNoException().isThrownBy(() -> cli.parse(new String[]{"-e"}));
}
@Test
public void should_enable_debug_mode() {
- cli.parse(new String[] {"-X"});
+ cli.parse(new String[]{"-X"});
assertThat(cli.isDebugEnabled()).isTrue();
- assertThat(cli.properties().get("sonar.verbose")).isEqualTo("true");
+ assertThat(cli.properties()).containsEntry("sonar.verbose", "true");
}
@Test
public void should_enable_debug_mode_full() {
- cli.parse(new String[] {"--debug"});
+ cli.parse(new String[]{"--debug"});
assertThat(cli.isDebugEnabled()).isTrue();
- assertThat(cli.properties().get("sonar.verbose")).isEqualTo("true");
+ assertThat(cli.properties()).containsEntry("sonar.verbose", "true");
}
@Test
public void should_show_version() {
- cli.parse(new String[] {"-v"});
+ cli.parse(new String[]{"-v"});
assertThat(cli.isDisplayVersionOnly()).isTrue();
}
@Test
public void should_show_version_full() {
- cli.parse(new String[] {"--version"});
+ cli.parse(new String[]{"--version"});
assertThat(cli.isDisplayVersionOnly()).isTrue();
}
@Test
public void should_enable_stacktrace_log() {
- cli.parse(new String[] {"-e"});
+ cli.parse(new String[]{"-e"});
assertThat(cli.isDebugEnabled()).isFalse();
assertThat(cli.properties().get("sonar.verbose")).isNull();
}
@Test
public void should_enable_stacktrace_log_full() {
- cli.parse(new String[] {"--errors"});
+ cli.parse(new String[]{"--errors"});
assertThat(cli.isDebugEnabled()).isFalse();
assertThat(cli.properties().get("sonar.verbose")).isNull();
}
@Test
public void should_parse_from_argument() {
- cli.parse(new String[] {"--from=ScannerMSBuild/4.8"});
+ cli.parse(new String[]{"--from=ScannerMSBuild/4.8"});
assertThat(cli.getInvokedFrom()).isNotEmpty();
assertThat(cli.getInvokedFrom()).isEqualTo("ScannerMSBuild/4.8");
}
@Test
public void from_argument_is_only_from_let_value_empty() {
- cli.parse(new String[] {"--from="});
+ cli.parse(new String[]{"--from="});
assertThat(cli.getInvokedFrom()).isEmpty();
}
@@ -142,7 +136,7 @@ public class CliTest {
public void should_show_usage() {
logs = mock(Logs.class);
cli = new Cli(exit, logs);
- cli.parse(new String[] {"-h"});
+ cli.parse(new String[]{"-h"});
verify(logs).info("usage: sonar-scanner [options]");
verify(exit).exit(Exit.SUCCESS);
}
@@ -151,7 +145,7 @@ public class CliTest {
public void should_show_usage_full() {
logs = mock(Logs.class);
cli = new Cli(exit, logs);
- cli.parse(new String[] {"--help"});
+ cli.parse(new String[]{"--help"});
verify(logs).info("usage: sonar-scanner [options]");
verify(exit).exit(Exit.SUCCESS);
}
@@ -160,7 +154,7 @@ public class CliTest {
public void should_show_usage_on_bad_syntax() {
logs = mock(Logs.class);
cli = new Cli(exit, logs);
- cli.parse(new String[] {"-w"});
+ cli.parse(new String[]{"-w"});
verify(logs).error("Unrecognized option: -w");
verify(logs).info("usage: sonar-scanner [options]");
verify(exit).exit(Exit.INTERNAL_ERROR);
@@ -168,7 +162,7 @@ public class CliTest {
@Test
public void should_enable_embedded_mode() {
- cli.parse(new String[] {"--embedded"});
+ cli.parse(new String[]{"--embedded"});
assertThat(cli.isEmbedded()).isTrue();
}
}