private boolean displayVersionOnly = false;
private boolean displayStackTrace = false;
private boolean interactive = false;
- private Properties props = new Properties();
- private final Exit exit;
- private Logs logger;
+ private final Properties props = new Properties();
+ private final Shutdown shutdown;
+ private final Logs logger;
- public Cli(Exit exit, Logs logger) {
- this.exit = exit;
+ public Cli(Shutdown shutdown, Logs logger) {
+ this.shutdown = shutdown;
this.logger = logger;
}
logger.info(" -v,--version Display version information");
logger.info(" -X,--debug Produce execution debug output");
logger.info(" -i,--interactive Run interactively");
- exit.exit(Exit.SUCCESS);
+ shutdown.exit(Exit.SUCCESS);
}
}
import static org.fest.assertions.Assertions.assertThat;
public class CliTest {
- Exit exit = mock(Exit.class);
+ Shutdown shutdown = mock(Shutdown.class);
Logs logs = new Logs();
- Cli cli = new Cli(exit, logs);
+ Cli cli = new Cli(shutdown, logs);
@Test
public void should_parse_empty_arguments() {
@Test
public void should_extract_properties() {
- cli.parse(new String[]{"-D", "foo=bar", "--define", "hello=world", "-Dboolean"});
+ 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");
}
-
+
@Test
public void dont_allow_interactive_fork() {
- cli.parse(new String[]{"-i", "-DsonarRunner.mode=fork"});
+ cli.parse(new String[] {"-i", "-DsonarRunner.mode=fork"});
cli.verify();
- verify(exit).exit(Exit.SUCCESS);
+ verify(shutdown).exit(Exit.SUCCESS);
}
@Test
public void should_parse_optional_task() {
- cli.parse(new String[]{"-D", "foo=bar"});
+ cli.parse(new String[] {"-D", "foo=bar"});
assertThat(cli.properties().get("sonar.task")).isNull();
- cli.parse(new String[]{"views", "-D", "foo=bar"});
+ cli.parse(new String[] {"views", "-D", "foo=bar"});
assertThat(cli.properties().get("sonar.task")).isEqualTo("views");
}
@Test
public void should_enable_debug_mode() {
- cli.parse(new String[]{"-X"});
+ cli.parse(new String[] {"-X"});
assertThat(cli.isDebugMode()).isTrue();
assertThat(cli.isDisplayStackTrace()).isTrue();
assertThat(cli.properties().get("sonar.verbose")).isEqualTo("true");
@Test
public void should_enable_stacktrace_log() {
- cli.parse(new String[]{"-e"});
+ cli.parse(new String[] {"-e"});
assertThat(cli.isDebugMode()).isFalse();
assertThat(cli.isDisplayStackTrace()).isTrue();
assertThat(cli.properties().get("sonar.verbose")).isNull();