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);
}
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();
}
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");
}
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();
}
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");
}
Aggregations