blob: 52e24844698be872a6d8e93a1f8a83cd4cc29fe7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*
* SonarScanner CLI
* Copyright (C) 2011-2021 SonarSource SA
* mailto:info AT sonarsource DOT 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 02110-1301, USA.
*/
package org.sonarsource.scanner.cli;
import org.junit.Before;
import org.junit.Test;
import org.sonarsource.scanner.cli.SystemInfo.System2;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class SystemInfoTest {
private final System2 mockSystem = mock(System2.class);
private final Logs logs = mock(Logs.class);
@Before
public void setUp() {
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_SCANNER_OPTS")).thenReturn("arg");
SystemInfo.print(logs);
verify(mockSystem).getProperty("java.version");
verify(mockSystem).getProperty("os.version");
verify(mockSystem).getenv("SONAR_SCANNER_OPTS");
verify(logs, never()).info("SonarScanner null");
verify(logs).info("SonarScanner " + ScannerVersion.version());
verify(logs).info("Java 1.9 oracle (64-bit)");
verify(logs).info("linux 2.5 x64");
verify(logs).info("SONAR_SCANNER_OPTS=arg");
verifyNoMoreInteractions(logs);
}
}
|