mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-19 19:21:27 +00:00
change getProperty(key, default) and add unit test
This commit is contained in:
@@ -29,12 +29,8 @@ public class SubstitutingProperties extends PropertiesDecorator {
|
||||
|
||||
@Override
|
||||
public String getProperty(String key, String defaultValue) {
|
||||
var value = delegate.getProperty(key, defaultValue);
|
||||
if (key.startsWith("cryptomator.") && value != null) {
|
||||
return process(value);
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
var result = getProperty(key);
|
||||
return result != null ? result : defaultValue;
|
||||
}
|
||||
|
||||
//visible for testing
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SubstitutingPropertiesTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@DisplayName("Properties not starting with \"cryptomator.\" are not processed")
|
||||
@ValueSource(strings = {"example.foo","cryptomatorSomething.foo","org.cryptomator.foo","cryPtoMAtor.foo"})
|
||||
@ValueSource(strings = {"example.foo", "cryptomatorSomething.foo", "org.cryptomator.foo", "cryPtoMAtor.foo"})
|
||||
public void testNoProcessingOnNotCryptomator(String propKey) {
|
||||
var props = new Properties();
|
||||
props.setProperty(propKey, "someValue");
|
||||
@@ -92,6 +92,19 @@ public class SubstitutingPropertiesTest {
|
||||
inTest.getProperty("cryptomator.prop");
|
||||
Mockito.verify(inTest).process("someValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Default value is not processed")
|
||||
public void testNoProcessingDefault() {
|
||||
var props = Mockito.mock(Properties.class);
|
||||
Mockito.when(props.getProperty("cryptomator.prop")).thenReturn(null);
|
||||
inTest = Mockito.spy(new SubstitutingProperties(props, Map.of()));
|
||||
Mockito.doReturn("someValue").when(inTest).process(Mockito.anyString());
|
||||
|
||||
var result = inTest.getProperty("cryptomator.prop", "a default");
|
||||
Assertions.assertEquals("a default", result);
|
||||
Mockito.verify(inTest, Mockito.never()).process(Mockito.any());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user