readd unit tests for Environment.java

This commit is contained in:
Armin Schrenk
2023-06-29 18:13:54 +02:00
parent ce596698e3
commit 9b0c940195
3 changed files with 46 additions and 7 deletions
@@ -13,6 +13,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
@DisplayName("Environment Variables Test")
public class EnvironmentTest {
@@ -34,8 +35,8 @@ public class EnvironmentTest {
}
@Nested
@DisplayName("Path Lists")
public class SettingsPath {
@DisplayName("Testing parsing path lists")
public class PathLists {
@Test
@DisplayName("test.path.property=")
@@ -48,7 +49,7 @@ public class EnvironmentTest {
@Test
@DisplayName("test.path.property=/foo/bar/test")
public void testSingleAbsolutePath() {
public void testSinglePath() {
System.setProperty("test.path.property", "/foo/bar/test");
List<Path> result = env.getPaths("test.path.property").toList();
@@ -56,6 +57,45 @@ public class EnvironmentTest {
MatcherAssert.assertThat(result, Matchers.hasItem(Paths.get("/foo/bar/test")));
}
@Test
@DisplayName("test.path.property=/foo/bar/test:/bar/nez/tost")
public void testTwoPaths() {
System.setProperty("test.path.property", "/foo/bar/test:bar/nez/tost");
List<Path> result = env.getPaths("test.path.property").toList();
MatcherAssert.assertThat(result, Matchers.hasSize(2));
MatcherAssert.assertThat(result, Matchers.hasItems(Path.of("/foo/bar/test"), Path.of("bar/nez/tost")));
}
}
@Nested
public class VariablesContainingPathLists {
@Test
public void testSettingsPath() {
Mockito.doReturn(Stream.of()).when(env).getPaths(Mockito.anyString());
env.getSettingsPath();
Mockito.verify(env).getPaths("cryptomator.settingsPath");
}
@Test
public void testP12Path() {
Mockito.doReturn(Stream.of()).when(env).getPaths(Mockito.anyString());
env.getP12Path();
Mockito.verify(env).getPaths("cryptomator.p12Path");
}
@Test
public void testIpcSocketPath() {
Mockito.doReturn(Stream.of()).when(env).getPaths(Mockito.anyString());
env.getIpcSocketPath();
Mockito.verify(env).getPaths("cryptomator.ipcSocketPath");
}
@Test
public void testKeychainPath() {
Mockito.doReturn(Stream.of()).when(env).getPaths(Mockito.anyString());
env.getKeychainPath();
Mockito.verify(env).getPaths("cryptomator.integrationsWin.keychainPaths");
}
}
}