Fix EngineConfiguration unit test

This commit is contained in:
JeremyStar™ 2024-06-27 21:02:35 +02:00
parent 2b689f8267
commit 8c0ebacd2b
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 50 additions and 6 deletions

View file

@ -20,10 +20,10 @@
package de.staropensource.sosengine.base;
import de.staropensource.sosengine.base.classes.SubsystemConfiguration;
import de.staropensource.sosengine.base.logging.Logger;
import de.staropensource.sosengine.base.types.CodePart;
import de.staropensource.sosengine.base.classes.logging.LogIssuer;
import de.staropensource.sosengine.base.classes.logging.LogLevel;
import de.staropensource.sosengine.base.logging.Logger;
import de.staropensource.sosengine.base.types.CodePart;
import de.staropensource.sosengine.base.utility.PropertyParser;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
@ -371,4 +371,11 @@ public final class EngineConfiguration implements SubsystemConfiguration {
}
}
}
/**
* Clears {@code instance}. Used in unit tests.
*/
private static void clearInstance() {
instance = null;
}
}

View file

@ -1,3 +1,22 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Contributors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.sosengine.base.srctests;
import de.staropensource.sosengine.base.EngineConfiguration;
@ -5,9 +24,14 @@ import de.staropensource.sosengine.base.classes.logging.LogLevel;
import de.staropensource.sosengine.unittests.UnitLogger;
import org.jetbrains.annotations.NotNull;
import org.joor.Reflect;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import static org.junit.jupiter.api.Assertions.*;
@ -39,7 +63,7 @@ class EngineConfigurationTest {
*/
@AfterEach
void clearClass() {
Reflect.on(EngineConfiguration.getInstance()).set("instance", null);
Reflect.onClass(EngineConfiguration.class).call("clearInstance");
}
/**
@ -53,18 +77,31 @@ class EngineConfigurationTest {
Map<@NotNull String, @NotNull Object[]> settings = new HashMap<>();
Map<@NotNull String, @NotNull Object> defaultValues = new HashMap<>();
// Format: value (string), expected value
settings.put("debug", new Object[]{ "true", Boolean.TRUE });
settings.put("debugEvents", 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%" });
settings.put("loggerImmediateShutdown", new Object[]{ "true", Boolean.TRUE });
settings.put("loggerForceStandardOutput", new Object[]{ "true", Boolean.TRUE });
settings.put("loggerPollingSpeed", new Object[]{ "9999", 9999 });
settings.put("optimizeLogging", new Object[]{ "false", Boolean.FALSE });
settings.put("optimizeEvents", new Object[]{ "false", Boolean.FALSE });
// Load default configuration
EngineConfiguration.getInstance().loadDefaultConfiguration();
// Save default values
for (String setting : settings.keySet())
for (String setting : settings.keySet()) {
if (EngineConfiguration.getInstance().getSetting(setting) == null) {
assertTrue(true, "Setting \"" + setting + "\" does not exist");
}
//noinspection DataFlowIssue // we do check getSetting you dumb ass
defaultValues.put(setting, EngineConfiguration.getInstance().getSetting(setting));
}
// Load custom configuration
Properties properties = new Properties();