aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-01-11 16:14:39 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2016-01-11 16:14:39 +0100
commit5e187f8dc1099ce63c00b9185b9a8a8d9ce92f92 (patch)
treec976e3ce1b391dd4d74ce2c2c6522ae1a0e16e2e /src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java
parentef4271a905f1a14f0f87c555e685e0744dec7d32 (diff)
downloadsonar-scanner-cli-5e187f8dc1099ce63c00b9185b9a8a8d9ce92f92.tar.gz
sonar-scanner-cli-5e187f8dc1099ce63c00b9185b9a8a8d9ce92f92.zip
Update groupId, artifactId and packages
Diffstat (limited to 'src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java')
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java b/src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java
new file mode 100644
index 0000000..67bbf35
--- /dev/null
+++ b/src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java
@@ -0,0 +1,97 @@
+/*
+ * SonarQube Scanner
+ * Copyright (C) 2011 SonarSource
+ * sonarqube@googlegroups.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonarsource.scanner.cli;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+import org.sonar.runner.api.RunnerVersion;
+import org.sonarsource.scanner.cli.Logs;
+import org.sonarsource.scanner.cli.SystemInfo;
+import org.sonarsource.scanner.cli.SystemInfo.System2;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class SystemInfoTest {
+ System2 mockSystem;
+ Logs logs;
+
+ @Before
+ public void setUp() {
+ mockSystem = mock(System2.class);
+ logs = mock(Logs.class);
+ SystemInfo.setSystem(mockSystem);
+ }
+
+ @Test
+ public void test_java() {
+ mockJava();
+ assertThat(SystemInfo.java()).isEqualTo("Java 1.9 oracle (64-bit)");
+
+ when(mockSystem.getProperty("sun.arch.data.model")).thenReturn("32");
+ assertThat(SystemInfo.java()).isEqualTo("Java 1.9 oracle (32-bit)");
+
+ when(mockSystem.getProperty("sun.arch.data.model")).thenReturn(null);
+ assertThat(SystemInfo.java()).isEqualTo("Java 1.9 oracle");
+ }
+
+ @Test
+ public void test_os() {
+ mockOs();
+
+ assertThat(SystemInfo.os()).isEqualTo("linux 2.5 x64");
+ }
+
+ private void mockJava() {
+ when(mockSystem.getProperty("java.version")).thenReturn("1.9");
+ when(mockSystem.getProperty("java.vendor")).thenReturn("oracle");
+ when(mockSystem.getProperty("sun.arch.data.model")).thenReturn("64");
+ }
+
+ private void mockOs() {
+ when(mockSystem.getProperty("os.version")).thenReturn("2.5");
+ when(mockSystem.getProperty("os.arch")).thenReturn("x64");
+ when(mockSystem.getProperty("os.name")).thenReturn("linux");
+ }
+
+ @Test
+ public void should_print() {
+ mockOs();
+ mockJava();
+ when(mockSystem.getenv("SONAR_RUNNER_OPTS")).thenReturn("arg");
+
+ SystemInfo.print(logs);
+
+ verify(mockSystem).getProperty("java.version");
+ verify(mockSystem).getProperty("os.version");
+ verify(mockSystem).getenv("SONAR_RUNNER_OPTS");
+
+ verify(logs).info("SonarQube Runner " + RunnerVersion.version());
+ verify(logs).info("Java 1.9 oracle (64-bit)");
+ verify(logs).info("linux 2.5 x64");
+ verify(logs).info("SONAR_RUNNER_OPTS=arg");
+ verifyNoMoreInteractions(logs);
+ }
+}