forked from mockito/mockito
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlatformUtilsTest.java
90 lines (80 loc) · 3.36 KB
/
PlatformUtilsTest.java
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
/*
* Copyright (c) 2023 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.creation.bytebuddy;
import java.util.Properties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.parallel.Isolated;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Ashley Scopes
*/
@Isolated("modifies system properties temporarily")
class PlatformUtilsTest {
Properties globalProperties;
@BeforeEach
void setUp() {
globalProperties = new Properties();
globalProperties.putAll(System.getProperties());
System.getProperties().clear();
}
@AfterEach
void tearDown() {
System.getProperties().clear();
System.getProperties().putAll(globalProperties);
}
@CsvSource(
value = {
"java.specification.vendor, expected result",
" android, true",
" AnDrOId, true",
" anythingElse, false",
" , false",
},
useHeadersInDisplayName = true)
@ParameterizedTest
void isAndroidPlatform_returns_expected_value(String vendor, boolean result) {
// Given
setProperty("java.specification.vendor", vendor);
// Then
assertThat(PlatformUtils.isAndroidPlatform()).isEqualTo(result);
}
@CsvSource(
value = {
" os.name, java.home, expected result",
" linux, /data/data/com.termux/whatever, true",
" linux, /foo/bar/com.termux/somedir, true",
" LINUX, /data/data/com.termux/whatever, true",
" Linux, /foo/bar/com.termux/somedir, true",
"Mac OS X 13.0, /foo/bar/com.termux/somedir, false",
" Windows 10, /foo/bar/com.termux/somedir, false",
" OS/2, /foo/bar/com.termux/somedir, false",
" Linux, /usr/share/java, false",
" , , false",
" foo, , false",
" , foo, false",
" linux, , false",
" , /data/data/com.termux/whatever, false",
},
useHeadersInDisplayName = true)
@ParameterizedTest
void isProbablyTermuxEnvironment_returns_expected_value(
String os, String javaHome, boolean result) {
// Given
setProperty("os.name", os);
setProperty("java.home", javaHome);
// Then
assertThat(PlatformUtils.isProbablyTermuxEnvironment()).isEqualTo(result);
}
static void setProperty(String name, String value) {
if (value == null) {
System.clearProperty(name);
} else {
System.setProperty(name, value);
}
}
}