-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEnvironmentVariableUtilTest.java
More file actions
42 lines (29 loc) · 1.34 KB
/
EnvironmentVariableUtilTest.java
File metadata and controls
42 lines (29 loc) · 1.34 KB
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
package org.utplsql.api;
import org.junit.jupiter.api.Test;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
class EnvironmentVariableUtilTest {
@Test
void testGetVariableFromEnvironment() {
// Let's find an environment variable which is not in Properties list and not empty
Set<Object> props = System.getProperties().keySet();
Optional<Map.Entry<String, String>> envVariable = System.getenv().entrySet().stream()
.filter((e) -> !props.contains(e.getKey()) && e.getValue() != null && !e.getValue().isEmpty())
.findFirst();
if ( !envVariable.isPresent() )
fail ("Can't test for there is no environment variable not overridden by property");
assertEquals(envVariable.get().getValue(), EnvironmentVariableUtil.getEnvValue(envVariable.get().getKey()));
}
@Test
void testGetVariableFromProperty() {
System.setProperty("PATH", "MyPath");
assertEquals("MyPath", EnvironmentVariableUtil.getEnvValue("PATH"));
}
@Test
void testGetVariableFromDefault() {
assertEquals("defaultValue", EnvironmentVariableUtil.getEnvValue("RANDOM"+String.valueOf(System.currentTimeMillis()), "defaultValue"));
}
}