more unit tests

This commit is contained in:
Armin Schrenk
2023-06-29 18:20:25 +02:00
parent 9b0c940195
commit 24fc2888ef

View File

@@ -1,6 +1,8 @@
package org.cryptomator.common;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
@@ -8,8 +10,10 @@ import java.util.Map;
public class LazyProcessedPropertiesTest {
LazyProcessedProperties inTest;
@ParameterizedTest
@CsvSource(value = {"org.example.@{mytest1}.test, org.example.@{mytest1}.test", //
@DisplayName("Test template replacement")
@CsvSource(value = {"unknown.@{testToken}.test, unknown.@{testToken}.test", //
"@{only*words*digits*under_score\\},@{only*words*digits*under_score\\}", //
"C:\\Users\\@{appdir}\\dir, C:\\Users\\foobar\\dir", //
"@{@{appdir}},@{foobar}", //
@@ -20,4 +24,25 @@ public class LazyProcessedPropertiesTest {
Assertions.assertEquals(result, expected);
}
@Test
@DisplayName("@{userhome} is replaced with the user home directory")
public void testUserhome(){
var expected = System.getProperty("user.home");
inTest = new LazyProcessedProperties(System.getProperties(), Map.of());
var result = inTest.process("@{userhome}");
Assertions.assertEquals(result, expected);
}
@DisplayName("Other keywords are replaced accordingly")
@ParameterizedTest(name = "Token \"{0}\" replaced with content of {1}")
@CsvSource(value = {"appdir, APPDIR, foobar",
"appdata, APPDATA, bazbaz",
"localappdata, LOCALAPPDATA, boboAlice"})
public void testAppDir(String token, String envName, String expected){
inTest = new LazyProcessedProperties(System.getProperties(), Map.of(envName, expected));
var result = inTest.process("@{"+token+"}");
Assertions.assertEquals(result, expected);
}
}