@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- when(scannerFactory.create(any(Properties.class))).thenReturn(scanner);
+ when(scannerFactory.create(any(Properties.class), any(String.class))).thenReturn(scanner);
when(conf.properties()).thenReturn(properties);
}
@Test
public void should_execute_runner() {
+ when(cli.getInvokedFrom()).thenReturn("");
Main main = new Main(exit, cli, conf, scannerFactory, logs);
main.execute();
verify(exit).exit(Exit.SUCCESS);
- verify(scannerFactory).create(properties);
+ verify(scannerFactory).create(properties, "");
verify(scanner, times(1)).start();
verify(scanner, times(1)).execute((Map) properties);
Exception e = new NullPointerException("NPE");
e = new IllegalStateException("Error", e);
doThrow(e).when(runner).execute(any());
- when(scannerFactory.create(any(Properties.class))).thenReturn(runner);
+ when(cli.getInvokedFrom()).thenReturn("");
+ when(scannerFactory.create(any(Properties.class), any(String.class))).thenReturn(runner);
when(cli.isDebugEnabled()).thenReturn(true);
Main main = new Main(exit, cli, conf, scannerFactory, logs);
main.execute();
Exception e = new NullPointerException("NPE");
e = new IllegalStateException("Error", e);
doThrow(e).when(runner).start();
+ when(cli.getInvokedFrom()).thenReturn("");
when(cli.isDebugEnabled()).thenReturn(true);
- when(scannerFactory.create(any(Properties.class))).thenReturn(runner);
+ when(scannerFactory.create(any(Properties.class), any(String.class))).thenReturn(runner);
Main main = new Main(exit, cli, conf, scannerFactory, logs);
main.execute();
private void testException(Exception e, boolean debugEnabled, boolean isEmbedded, int expectedExitCode) {
when(cli.isDebugEnabled()).thenReturn(debugEnabled);
when(cli.isEmbedded()).thenReturn(isEmbedded);
+ when(cli.getInvokedFrom()).thenReturn("");
EmbeddedScanner runner = mock(EmbeddedScanner.class);
doThrow(e).when(runner).execute(any());
- when(scannerFactory.create(any(Properties.class))).thenReturn(runner);
+
+ when(scannerFactory.create(any(Properties.class), any(String.class))).thenReturn(runner);
Main main = new Main(exit, cli, conf, scannerFactory, logs);
main.execute();
public void should_only_display_version() {
Properties p = new Properties();
when(cli.isDisplayVersionOnly()).thenReturn(true);
+ when(cli.getInvokedFrom()).thenReturn("");
when(conf.properties()).thenReturn(p);
Main main = new Main(exit, cli, conf, scannerFactory, logs);
InOrder inOrder = Mockito.inOrder(exit, scannerFactory);
inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
- inOrder.verify(scannerFactory, times(1)).create(p);
+ inOrder.verify(scannerFactory, times(1)).create(p, "");
inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
}
Properties p = new Properties();
p.setProperty(ScanProperties.SKIP, "true");
when(conf.properties()).thenReturn(p);
+ when(cli.getInvokedFrom()).thenReturn("");
Main main = new Main(exit, cli, conf, scannerFactory, logs);
main.execute();
InOrder inOrder = Mockito.inOrder(exit, scannerFactory);
inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
- inOrder.verify(scannerFactory, times(1)).create(p);
+ inOrder.verify(scannerFactory, times(1)).create(p, "");
inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
}
when(scanner.serverVersion()).thenReturn("5.5");
Properties p = new Properties();
when(cli.isDisplayVersionOnly()).thenReturn(true);
+ when(cli.getInvokedFrom()).thenReturn("");
when(conf.properties()).thenReturn(p);
Main main = new Main(exit, cli, conf, scannerFactory, logs);
Properties p = new Properties();
when(conf.properties()).thenReturn(p);
when(conf.isSonarCloud(null)).thenReturn(true);
+ when(cli.getInvokedFrom()).thenReturn("");
Main main = new Main(exit, cli, conf, scannerFactory, logs);
main.execute();
Properties p = new Properties();
p.put(propKey, propValue);
when(conf.properties()).thenReturn(p);
+ when(cli.getInvokedFrom()).thenReturn("");
Main main = new Main(exit, cli, conf, scannerFactory, logs);
main.execute();
public class ScannerFactoryTest {
- private Properties props = new Properties();
- private Logs logs = mock(Logs.class);
+ private final Properties props = new Properties();
+ private final Logs logs = mock(Logs.class);
@Test
public void should_create_embedded_runner() {
props.setProperty("foo", "bar");
- EmbeddedScanner runner = new ScannerFactory(logs).create(props);
+ EmbeddedScanner runner = new ScannerFactory(logs).create(props, "");
assertThat(runner).isInstanceOf(EmbeddedScanner.class);
- assertThat(runner.globalProperties().get("foo")).isEqualTo("bar");
- assertThat(runner.app()).isEqualTo("ScannerCli");
+ assertThat(runner.globalProperties()).containsEntry("foo", "bar");
+ assertThat(runner.app()).isEqualTo("ScannerCLI");
+ assertThat(runner.appVersion()).isNotNull();
+ }
+
+ @Test
+ public void should_create_embedded_runner_with_scannername_from_argument() {
+ props.setProperty("foo", "bar");
+ EmbeddedScanner runner = new ScannerFactory(logs).create(props, "ScannerMSBuild/4.8.0");
+
+ assertThat(runner).isInstanceOf(EmbeddedScanner.class);
+ assertThat(runner.globalProperties()).containsEntry("foo", "bar");
+ assertThat(runner.app()).isEqualTo("ScannerMSBuild");
+ assertThat(runner.appVersion()).isEqualTo("4.8.0");
+ assertThat(runner.appVersion()).isNotNull();
+ }
+
+ @Test
+ public void should_create_embedded_runner_from_argument_is_not_regex_compliant_revert_to_default_scanner_name() {
+ props.setProperty("foo", "bar");
+ EmbeddedScanner runner = new ScannerFactory(logs).create(props, "ScannerMSBuild4.8.0");
+
+ assertThat(runner).isInstanceOf(EmbeddedScanner.class);
+ assertThat(runner.globalProperties()).containsEntry("foo", "bar");
+ assertThat(runner.app()).isEqualTo("ScannerCLI");
assertThat(runner.appVersion()).isNotNull();
}