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

View File

@@ -2,7 +2,6 @@ package org.cryptomator.common;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,7 +79,7 @@ public class Environment {
return getPaths(P12_PATH_PROP_NAME);
}
public Stream<Path> ipcSocketPath() {
public Stream<Path> getIpcSocketPath() {
return getPaths(IPC_SOCKET_PATH_PROP_NAME);
}
@@ -131,7 +130,7 @@ public class Environment {
}
// visible for testing
public Stream<Path> getPaths(String propertyName) {
Stream<Path> getPaths(String propertyName) {
Stream<String> rawSettingsPaths = getRawList(propertyName, PATH_LIST_SEP);
return rawSettingsPaths.filter(Predicate.not(Strings::isNullOrEmpty)).map(Path::of);
}

View File

@@ -94,7 +94,7 @@ public class Cryptomator {
* Attempts to create an IPC connection to a running Cryptomator instance and sends it the given args.
* If no external process could be reached, the args will be handled by the loopback IPC endpoint.
*/
try (var communicator = IpcCommunicator.create(env.ipcSocketPath().toList())) {
try (var communicator = IpcCommunicator.create(env.getIpcSocketPath().toList())) {
if (communicator.isClient()) {
communicator.sendHandleLaunchargs(List.of(args));
communicator.sendRevealRunningApp();

View File

@@ -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");
}
}
}