From 47c962738b94abfb9a75b129380fe602035faf3f Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 9 Jun 2024 13:43:30 +0200 Subject: [PATCH] Make EngineConfiguration test better --- .../srctests/EngineConfigurationTest.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/EngineConfigurationTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/EngineConfigurationTest.java index 91cbcfe..52e8826 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/EngineConfigurationTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/EngineConfigurationTest.java @@ -1,13 +1,12 @@ package de.staropensource.sosengine.base.srctests; import de.staropensource.sosengine.base.EngineConfiguration; +import de.staropensource.sosengine.base.types.LogLevel; import de.staropensource.sosengine.unittests.UnitLogger; import org.joor.Reflect; import org.junit.jupiter.api.*; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; +import java.util.*; import static org.junit.jupiter.api.Assertions.*; @@ -21,6 +20,10 @@ class EngineConfigurationTest { * The unit logger for this instance. */ private final UnitLogger logger = new UnitLogger(getClass()); + /** + * The property group for the base engine. + */ + private final String group = EngineConfiguration.getGroup(); /** * Initializes the {@link EngineConfiguration} class before each test. @@ -46,42 +49,39 @@ class EngineConfigurationTest { void testLoadConfiguration() { logger.testCall("testLoadConfiguration"); - EngineConfiguration config = EngineConfiguration.getInstance(); - String group = EngineConfiguration.getGroup(); - String[] keys = new String[]{ - "debug", - "debugShortcodeConverter", - "errorShortcodeConverter", - "loggerLevel", - "loggerTemplate" - }; + Map settings = new HashMap<>(); Map defaultValues = new HashMap<>(); + settings.put("debug", new Object[]{ "true", Boolean.TRUE }); + settings.put("debugShortcodeConverter", new Object[]{ "true", Boolean.TRUE }); + settings.put("errorShortcodeConverter", new Object[]{ "false", Boolean.FALSE }); + settings.put("loggerLevel", new Object[]{ "verbose", LogLevel.VERBOSE }); + settings.put("loggerTemplate", new Object[]{ "%log_path% says: %message%", "%log_path% says: %message%" }); + // Load default configuration - config.loadDefaultConfiguration(); + EngineConfiguration.getInstance().loadDefaultConfiguration(); // Save default values - for (String setting : keys) - defaultValues.put(setting, config.getSetting(setting)); + for (String setting : settings.keySet()) + defaultValues.put(setting, EngineConfiguration.getInstance().getSetting(setting)); // Load custom configuration Properties properties = new Properties(); - properties.setProperty(group + "debug", "true"); - properties.setProperty(group + "debugShortcodeConverter", "true"); - properties.setProperty(group + "errorShortcodeConverter", "false"); - properties.setProperty(group + "loggerLevel", "diagnostic"); - properties.setProperty(group + "loggerTemplate", "%log_path% says: %message%"); + for (String setting : settings.keySet()) + properties.setProperty(group + setting, (String) settings.get(setting)[0]); - config.loadConfiguration(properties); + EngineConfiguration.getInstance().loadConfiguration(properties); // Compare custom values against default ones - for (String setting : keys) { + for (String setting : settings.keySet()) { Object defaultValue = defaultValues.get(setting); - Object customValue = config.getSetting(setting); + Object customValue = EngineConfiguration.getInstance().getSetting(setting); - logger.diag("Comparing setting " + setting); + logger.diag("Comparing setting " + setting + "(not equals defaultValue)"); assertNotEquals(defaultValue, customValue); + logger.diag("Comparing setting " + setting + "(equals expected value)"); + assertEquals(settings.get(setting)[1], customValue); } } }