move properties based settings loader out of the way

This commit is contained in:
Jörg Prante 2022-01-05 17:33:05 +01:00
parent abe8e4adf8
commit 7b220eac39
7 changed files with 26 additions and 7 deletions

View file

@ -53,7 +53,7 @@ public class PropertiesSettingsLoader implements SettingsLoader {
@Override @Override
public boolean canLoad(String source) { public boolean canLoad(String source) {
return true; return source != null && source.charAt(0) == '#';
} }
public Map<String, String> load(BytesReference ref) throws IOException { public Map<String, String> load(BytesReference ref) throws IOException {

View file

@ -1 +0,0 @@
org.xbib.settings.content.PropertiesSettingsLoader

View file

@ -143,9 +143,17 @@ public class SettingsTest {
} }
@Test @Test
public void testPropertiesLoader() { public void testPropertiesLoaderFromResource() {
Settings settings = Settings.settingsBuilder() Settings settings = Settings.settingsBuilder()
.loadFromResource(".properties", new ByteArrayInputStream("a.b=c".getBytes(StandardCharsets.UTF_8))) .loadFromResource("properties", new ByteArrayInputStream("a.b=c".getBytes(StandardCharsets.UTF_8)))
.build();
assertEquals("{a.b=c}", settings.getAsMap().toString());
}
@Test
public void testPropertiesLoaderFromString() {
Settings settings = Settings.settingsBuilder()
.loadFromString("#\na.b=c")
.build(); .build();
assertEquals("{a.b=c}", settings.getAsMap().toString()); assertEquals("{a.b=c}", settings.getAsMap().toString());
} }

View file

@ -0,0 +1 @@
org.xbib.settings.content.PropertiesSettingsLoader

View file

@ -1,6 +1,10 @@
package org.xbib.settings.datastructures.json.test; package org.xbib.settings.datastructures.json.test;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.datastructures.json.tiny.JsonBuilder;
import org.xbib.settings.Settings; import org.xbib.settings.Settings;
import org.xbib.settings.SettingsLoader; import org.xbib.settings.SettingsLoader;
import org.xbib.settings.datastructures.json.JsonSettingsLoader; import org.xbib.settings.datastructures.json.JsonSettingsLoader;

View file

@ -44,6 +44,6 @@ public class PropertiesSettingsLoader implements SettingsLoader {
@Override @Override
public boolean canLoad(String source) { public boolean canLoad(String source) {
return true; return source != null && source.charAt(0) == '#';
} }
} }

View file

@ -116,11 +116,18 @@ public class SettingsTest {
} }
@Test @Test
public void testPropertiesLoader() { public void testPropertiesLoaderFromResource() {
Settings settings = Settings.settingsBuilder() Settings settings = Settings.settingsBuilder()
.loadFromResource(".properties", new ByteArrayInputStream("a.b=c".getBytes(StandardCharsets.UTF_8))) .loadFromResource("properties", new ByteArrayInputStream("a.b=c".getBytes(StandardCharsets.UTF_8)))
.build(); .build();
assertEquals("{a.b=c}", settings.getAsMap().toString()); assertEquals("{a.b=c}", settings.getAsMap().toString());
} }
@Test
public void testPropertiesLoaderFromString() {
Settings settings = Settings.settingsBuilder()
.loadFromString("#\na.b=c")
.build();
assertEquals("{a.b=c}", settings.getAsMap().toString());
}
} }