Search in sources :

Example 11 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class ApiVersionTest method throw_ISE_if_fail_to_load_version.

@Test
public void throw_ISE_if_fail_to_load_version() throws Exception {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Can not load /sonar-api-version.txt from classpath");
    System2 system = spy(System2.class);
    when(system.getResource(anyString())).thenReturn(new File("target/unknown").toURI().toURL());
    ApiVersion.load(system);
}
Also used : System2(org.sonar.api.utils.System2) File(java.io.File) Test(org.junit.Test)

Example 12 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class CommandTest method should_use_cmd_for_new_shell_on_windows.

@Test
public void should_use_cmd_for_new_shell_on_windows() {
    System2 system = mock(System2.class);
    when(system.isOsWindows()).thenReturn(true);
    Command command = new Command("foo.bat", system);
    command.setNewShell(true);
    assertThat(command.toCommandLine()).isEqualTo("cmd /C call foo.bat");
    assertThat(command.isNewShell()).isTrue();
}
Also used : System2(org.sonar.api.utils.System2) Test(org.junit.Test)

Example 13 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class CommandTest method override_env_variables.

@Test
public void override_env_variables() {
    System2 system = mock(System2.class);
    when(system.envVariables()).thenReturn(ImmutableMap.of("JAVA_HOME", "/default/path/to/java"));
    Command command = new Command("java", system);
    command.setEnvironmentVariable("JAVA_HOME", "/new/path/to/java");
    assertThat(command.getEnvironmentVariables().get("JAVA_HOME")).isEqualTo("/new/path/to/java");
}
Also used : System2(org.sonar.api.utils.System2) Test(org.junit.Test)

Example 14 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class CommandTest method should_use_sh_for_new_shell_on_unix.

@Test
public void should_use_sh_for_new_shell_on_unix() {
    System2 system = mock(System2.class);
    when(system.isOsWindows()).thenReturn(false);
    Command command = new Command("foo.sh", system);
    command.setNewShell(true);
    assertThat(command.toCommandLine()).isEqualTo("sh foo.sh");
    assertThat(command.isNewShell()).isTrue();
}
Also used : System2(org.sonar.api.utils.System2) Test(org.junit.Test)

Example 15 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class ProjectAnalysisInfoTest method testSimpleDate.

@Test
public void testSimpleDate() {
    Settings settings = new MapSettings();
    settings.appendProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
    settings.appendProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "version");
    System2 system = mock(System2.class);
    ProjectAnalysisInfo info = new ProjectAnalysisInfo(settings, system);
    info.start();
    LocalDate date = LocalDate.of(2017, 1, 1);
    assertThat(info.analysisDate()).isEqualTo(Date.from(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
    assertThat(info.analysisVersion()).isEqualTo("version");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) System2(org.sonar.api.utils.System2) LocalDate(java.time.LocalDate) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Aggregations

System2 (org.sonar.api.utils.System2)15 Before (org.junit.Before)8 Test (org.junit.Test)7 DbClient (org.sonar.db.DbClient)3 File (java.io.File)2 WsTester (org.sonar.server.ws.WsTester)2 Throwables (com.google.common.base.Throwables)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LocalDate (java.time.LocalDate)1 Arrays (java.util.Arrays)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Properties (java.util.Properties)1 LongStream (java.util.stream.LongStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1