From 7b220eac39cf2588a1e22321f15368f32c538576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Wed, 5 Jan 2022 17:33:05 +0100 Subject: [PATCH] move properties based settings loader out of the way --- .../settings/content/PropertiesSettingsLoader.java | 2 +- .../services/org.xbib.settings.SettingsLoader | 1 - .../org/xbib/settings/content/test/SettingsTest.java | 12 ++++++++++-- .../services/org.xbib.settings.SettingsLoader | 1 + .../datastructures/json/test/JsonSettingsTest.java | 4 ++++ .../datastructures/PropertiesSettingsLoader.java | 2 +- .../settings/datastructures/test/SettingsTest.java | 11 +++++++++-- 7 files changed, 26 insertions(+), 7 deletions(-) delete mode 100644 settings-content/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader create mode 100644 settings-content/src/test/resources/META-INF/services/org.xbib.settings.SettingsLoader diff --git a/settings-content/src/main/java/org/xbib/settings/content/PropertiesSettingsLoader.java b/settings-content/src/main/java/org/xbib/settings/content/PropertiesSettingsLoader.java index 54476d4..ed2e83a 100644 --- a/settings-content/src/main/java/org/xbib/settings/content/PropertiesSettingsLoader.java +++ b/settings-content/src/main/java/org/xbib/settings/content/PropertiesSettingsLoader.java @@ -53,7 +53,7 @@ public class PropertiesSettingsLoader implements SettingsLoader { @Override public boolean canLoad(String source) { - return true; + return source != null && source.charAt(0) == '#'; } public Map load(BytesReference ref) throws IOException { diff --git a/settings-content/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader b/settings-content/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader deleted file mode 100644 index 9307b19..0000000 --- a/settings-content/src/main/resources/META-INF/services/org.xbib.settings.SettingsLoader +++ /dev/null @@ -1 +0,0 @@ -org.xbib.settings.content.PropertiesSettingsLoader \ No newline at end of file diff --git a/settings-content/src/test/java/org/xbib/settings/content/test/SettingsTest.java b/settings-content/src/test/java/org/xbib/settings/content/test/SettingsTest.java index 9ba6d8f..58e6c63 100644 --- a/settings-content/src/test/java/org/xbib/settings/content/test/SettingsTest.java +++ b/settings-content/src/test/java/org/xbib/settings/content/test/SettingsTest.java @@ -143,9 +143,17 @@ public class SettingsTest { } @Test - public void testPropertiesLoader() { + public void testPropertiesLoaderFromResource() { 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(); assertEquals("{a.b=c}", settings.getAsMap().toString()); } diff --git a/settings-content/src/test/resources/META-INF/services/org.xbib.settings.SettingsLoader b/settings-content/src/test/resources/META-INF/services/org.xbib.settings.SettingsLoader new file mode 100644 index 0000000..c86b654 --- /dev/null +++ b/settings-content/src/test/resources/META-INF/services/org.xbib.settings.SettingsLoader @@ -0,0 +1 @@ +org.xbib.settings.content.PropertiesSettingsLoader diff --git a/settings-datastructures-json/src/test/java/org/xbib/settings/datastructures/json/test/JsonSettingsTest.java b/settings-datastructures-json/src/test/java/org/xbib/settings/datastructures/json/test/JsonSettingsTest.java index 69e1426..b6033b1 100644 --- a/settings-datastructures-json/src/test/java/org/xbib/settings/datastructures/json/test/JsonSettingsTest.java +++ b/settings-datastructures-json/src/test/java/org/xbib/settings/datastructures/json/test/JsonSettingsTest.java @@ -1,6 +1,10 @@ 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.xbib.datastructures.json.tiny.JsonBuilder; import org.xbib.settings.Settings; import org.xbib.settings.SettingsLoader; import org.xbib.settings.datastructures.json.JsonSettingsLoader; diff --git a/settings-datastructures/src/main/java/org/xbib/settings/datastructures/PropertiesSettingsLoader.java b/settings-datastructures/src/main/java/org/xbib/settings/datastructures/PropertiesSettingsLoader.java index f6df055..b41cde5 100644 --- a/settings-datastructures/src/main/java/org/xbib/settings/datastructures/PropertiesSettingsLoader.java +++ b/settings-datastructures/src/main/java/org/xbib/settings/datastructures/PropertiesSettingsLoader.java @@ -44,6 +44,6 @@ public class PropertiesSettingsLoader implements SettingsLoader { @Override public boolean canLoad(String source) { - return true; + return source != null && source.charAt(0) == '#'; } } diff --git a/settings-datastructures/src/test/java/org/xbib/settings/datastructures/test/SettingsTest.java b/settings-datastructures/src/test/java/org/xbib/settings/datastructures/test/SettingsTest.java index d54b0bf..af7eac9 100644 --- a/settings-datastructures/src/test/java/org/xbib/settings/datastructures/test/SettingsTest.java +++ b/settings-datastructures/src/test/java/org/xbib/settings/datastructures/test/SettingsTest.java @@ -116,11 +116,18 @@ public class SettingsTest { } @Test - public void testPropertiesLoader() { + public void testPropertiesLoaderFromResource() { 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(); + assertEquals("{a.b=c}", settings.getAsMap().toString()); + } }