import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.sonar.runner.api.EmbeddedRunner;
+
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
public class MainTest {
@Mock
- private Shutdown exit;
+ private Shutdown shutdown;
@Mock
private Cli cli;
@Mock
@Test
public void should_execute_runner() {
- Main main = new Main(exit, cli, conf, runnerFactory, logs);
+ Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
main.execute();
- verify(exit).exit(Exit.SUCCESS);
+ verify(shutdown).exit(Exit.SUCCESS);
verify(runnerFactory).create(properties);
verify(runner, times(1)).start();
doThrow(e).when(runner).runAnalysis(any(Properties.class));
when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
- Main main = new Main(exit, cli, conf, runnerFactory, logs);
+ Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
main.execute();
verify(runner).stop();
- verify(exit).exit(Exit.ERROR);
- verify(logs).error("Caused by: NPE" );
-
+ verify(shutdown).exit(Exit.ERROR);
+ verify(logs).error("Caused by: NPE");
+
}
-
+
@Test
public void show_error_stacktrace() {
Exception e = new NullPointerException("NPE");
e = new IllegalStateException("Error", e);
when(cli.isDisplayStackTrace()).thenReturn(true);
-
+
EmbeddedRunner runner = mock(EmbeddedRunner.class);
doThrow(e).when(runner).runAnalysis(any(Properties.class));
when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
- Main main = new Main(exit, cli, conf, runnerFactory, logs);
+ Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
main.execute();
verify(runner).stop();
- verify(exit).exit(Exit.ERROR);
+ verify(shutdown).exit(Exit.ERROR);
verify(logs).error("Error during Sonar runner execution", e);
}
when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
when(cli.isInteractive()).thenReturn(true);
- Main main = new Main(exit, cli, conf, runnerFactory, logs);
+ Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
BufferedReader inputReader = mock(BufferedReader.class);
when(inputReader.readLine()).thenReturn("");
- when(exit.shouldExit()).thenReturn(false).thenReturn(true);
+ when(shutdown.shouldExit()).thenReturn(false).thenReturn(true);
main.setInputReader(inputReader);
main.execute();
verify(runner, times(2)).runAnalysis(any(Properties.class));
verify(runner).stop();
- verify(exit).exit(Exit.SUCCESS);
+ verify(shutdown).exit(Exit.SUCCESS);
}
@Test
when(cli.isDisplayVersionOnly()).thenReturn(true);
when(conf.properties()).thenReturn(p);
- Main main = new Main(exit, cli, conf, runnerFactory, logs);
+ Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
main.execute();
- InOrder inOrder = Mockito.inOrder(exit, runnerFactory);
+ InOrder inOrder = Mockito.inOrder(shutdown, runnerFactory);
- inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
+ inOrder.verify(shutdown, times(1)).exit(Exit.SUCCESS);
inOrder.verify(runnerFactory, times(1)).create(p);
- inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
+ inOrder.verify(shutdown, times(1)).exit(Exit.SUCCESS);
}
@Test(timeout = 30000)
when(cli.isDebugMode()).thenReturn(true);
when(cli.isDisplayStackTrace()).thenReturn(true);
- Main main = new Main(exit, cli, conf, runnerFactory, logs);
+ Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
main.execute();
verify(runner, times(1)).start();
*/
package org.sonar.runner.cli;
-import static org.mockito.Mockito.verify;
-import static org.fest.assertions.Assertions.assertThat;
-import static com.jayway.awaitility.Awaitility.await;
-
+import com.jayway.awaitility.Duration;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
-
-import com.jayway.awaitility.Duration;
-import org.mockito.MockitoAnnotations;
-import org.sonar.runner.cli.Exit;
-import org.sonar.runner.cli.Shutdown;
-import org.mockito.Mock;
-import org.junit.Test;
import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import static com.jayway.awaitility.Awaitility.await;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.verify;
public class ShutdownTest {
@Mock
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- shutdown = new Shutdown(exit);
+ shutdown = new Shutdown(exit, true);
}
@Test
@Test(timeout = 60_000)
public void testWaitReady() throws InterruptedException {
- shutdown = new Shutdown(exit, 100_000);
+ shutdown = new Shutdown(exit, true, 100_000);
shutdown.signalReady(false);
assertThat(shutdown.shouldExit()).isFalse();
@Test(timeout = 60_000)
public void testTimeout() throws InterruptedException {
- shutdown = new Shutdown(exit, 0);
+ shutdown = new Shutdown(exit, true, 0);
Thread t = new HookCaller();
t.start();