Fix unit tests

This commit is contained in:
JeremyStar™ 2024-07-29 19:58:41 +02:00
parent 006283acff
commit cbf434ed45
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
19 changed files with 159 additions and 223 deletions

View file

@ -18,9 +18,6 @@
*/
import java.nio.file.Files
// Plugins
plugins {
id("java")
@ -135,6 +132,11 @@ javadoc {
// Unit testing configuration
test {
useJUnitPlatform()
setMaxParallelForks(project.hasProperty("jobs") ? Integer.parseInt((String) project.property("jobs")) : 8)
setForkEvery(1)
setFailFast(true)
testLogging {
events("passed", "skipped", "failed")
}

View file

@ -411,13 +411,4 @@ public final class EngineConfiguration implements SubsystemConfiguration {
default -> { return null; }
}
}
/**
* Clears {@code instance}. Used in unit tests.
*
* @since v1-alpha1
*/
private static void clearInstance() {
instance = null;
}
}

View file

@ -89,8 +89,6 @@ public final class PlaceholderEngine {
placeholders.add(new DateMonth());
placeholders.add(new DateYear());
// engine_dependency_*
placeholders.add(new EngineDependencyLombok());
placeholders.add(new EngineDependencyJetbrainsAnnotations());
placeholders.add(new EngineDependencyJansi());
placeholders.add(new EngineDependencyLwjgl());
placeholders.add(new EngineDependencyReflections());
@ -164,13 +162,4 @@ public final class PlaceholderEngine {
public String process(@NotNull String text) {
return process(text, new ArrayList<>());
}
/**
* Clears {@code instance}. Used in unit tests.
*
* @since v1-alpha1
*/
private static void clearInstance() {
instance = null;
}
}

View file

@ -20,18 +20,11 @@
package de.staropensource.sosengine.base.srctests;
import de.staropensource.sosengine.base.EngineConfiguration;
import de.staropensource.sosengine.base.exceptions.UnexpectedThrowableException;
import de.staropensource.sosengine.base.exceptions.reflection.InvalidMethodException;
import de.staropensource.sosengine.base.reflection.Reflect;
import de.staropensource.sosengine.base.types.logging.LogLevel;
import de.staropensource.sosengine.unittests.UnitLogger;
import org.jetbrains.annotations.NotNull;
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.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@ -43,40 +36,19 @@ import static org.junit.jupiter.api.Assertions.*;
*/
@SuppressWarnings("unused")
@DisplayName("EngineConfiguration")
class EngineConfigurationTest {
/**
* The unit logger for this instance.
*/
private static final UnitLogger logger = new UnitLogger(EngineConfigurationTest.class);
class EngineConfigurationTest extends TestBase {
/**
* The property group for the base engine.
*/
private final String group = EngineConfiguration.getGroup();
/**
* Initializes the {@link EngineConfiguration} class before each test.
*/
@BeforeEach
void initializeClass() {
new EngineConfiguration();
}
/**
* Sets the {@link EngineConfiguration}#{@code instance} to {@code null} after each test.
*/
@AfterEach
void clearInstance() throws InvalidMethodException, UnexpectedThrowableException, InvocationTargetException {
Reflect.reflectOn(EngineConfiguration.class).getMethod("clearInstance").invoke();
}
/**
* Tests the method {@code loadConfiguration}.
*/
@Test
@DisplayName("Method loadConfiguration")
void testLoadConfiguration() {
logger.testCall("testLoadConfiguration");
getLogger().testCall("testLoadConfiguration");
Map<@NotNull String, @NotNull Object[]> settings = new HashMap<>();
Map<@NotNull String, @NotNull Object> defaultValues = new HashMap<>();
@ -120,9 +92,9 @@ class EngineConfigurationTest {
Object defaultValue = defaultValues.get(setting);
Object customValue = EngineConfiguration.getInstance().getSetting(setting);
logger.diag("Comparing setting " + setting + "(not equals defaultValue)");
getLogger().diag("Comparing setting " + setting + "(not equals defaultValue)");
assertNotEquals(defaultValue, customValue);
logger.diag("Comparing setting " + setting + "(equals expected value)");
getLogger().diag("Comparing setting " + setting + "(equals expected value)");
assertEquals(settings.get(setting)[1], customValue);
}
}

View file

@ -0,0 +1,72 @@
/*
* 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.Engine;
import de.staropensource.sosengine.unittests.UnitLogger;
import lombok.Getter;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
/**
* A class implemented by all tests.
*/
@SuppressWarnings({ "unused" })
public class TestBase {
/**
* Instance of this test class.
* -- GETTER --
* Returns the instance of this test class.
*/
@Getter
private static TestBase instance;
/**
* The unit logger for this test class.
* -- GETTER --
* Returns the unit logger for this test class.
*/
@Getter
private final UnitLogger logger = new UnitLogger(getClass());
/**
* Determines whether the engine should be automatically initialized or not.
*/
protected boolean doInitialization = true;
/**
* Constructs this class.
*/
public TestBase() {
// JUnit for some reason recreates the test class every time a test method is called
// Therefore we don't throw or complain here, instead we just override 'instance' and
// hope nothing breaks.
instance = this;
}
/**
* Initializes the engine before running tests.
*/
@BeforeEach
void initializeEngine() {
if (doInitialization && Engine.getInstance() == null)
new Engine();
}
}

View file

@ -21,12 +21,10 @@ package de.staropensource.sosengine.base.srctests.data.versioning;
import de.staropensource.sosengine.base.data.versioning.FourNumberVersioningSystem;
import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException;
import de.staropensource.sosengine.unittests.UnitLogger;
import de.staropensource.sosengine.base.srctests.TestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@ -36,13 +34,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/
@SuppressWarnings({ "unused" })
@DisplayName("FourNumberVersioningSystem")
public class FourNumberVersioningSystemTest {
/**
* The unit logger for this instance.
*/
private static final UnitLogger logger = new UnitLogger(FourNumberVersioningSystemTest.class);
private static final Logger log = LoggerFactory.getLogger(FourNumberVersioningSystemTest.class);
public class FourNumberVersioningSystemTest extends TestBase {
/**
* Tests the method {@code compare}.
*/
@ -58,14 +50,14 @@ public class FourNumberVersioningSystemTest {
"1.1.0.0, 1.1.1.1, 2",
})
void testCompare(String a, String b, int expected) throws Throwable {
logger.testCall("testCompare", a, b, expected);
getLogger().testCall("testCompare", a, b, expected);
try {
assertEquals(expected, new FourNumberVersioningSystem(a).compare(new FourNumberVersioningSystem(b)));
} catch (InvalidVersionStringException exception) {
logger.error("Got InvalidVersionStringException: " + exception.getMessage());
getLogger().error("Got InvalidVersionStringException: " + exception.getMessage());
if (exception.getThrowable() != null) {
logger.error("Original stack trace:");
getLogger().error("Original stack trace:");
throw exception.getThrowable();
}
fail("Got InvalidVersionStringException");

View file

@ -22,12 +22,10 @@ package de.staropensource.sosengine.base.srctests.data.versioning;
import de.staropensource.sosengine.base.data.versioning.OneNumberVersioningSystem;
import de.staropensource.sosengine.base.data.versioning.TwoNumberVersioningSystem;
import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException;
import de.staropensource.sosengine.unittests.UnitLogger;
import de.staropensource.sosengine.base.srctests.TestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@ -37,13 +35,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/
@SuppressWarnings({ "unused" })
@DisplayName("OneNumberVersioningSystem")
public class OneNumberVersioningSystemTest {
/**
* The unit logger for this instance.
*/
private static final UnitLogger logger = new UnitLogger(OneNumberVersioningSystemTest.class);
private static final Logger log = LoggerFactory.getLogger(OneNumberVersioningSystemTest.class);
public class OneNumberVersioningSystemTest extends TestBase {
/**
* Tests the method {@code compare}.
*/
@ -55,14 +47,14 @@ public class OneNumberVersioningSystemTest {
"1, 2, 2",
})
void testCompare(String a, String b, int expected) throws Throwable {
logger.testCall("testCompare", a, b, expected);
getLogger().testCall("testCompare", a, b, expected);
try {
assertEquals(expected, new OneNumberVersioningSystem(a).compare(new OneNumberVersioningSystem(b)));
} catch (InvalidVersionStringException exception) {
logger.error("Got InvalidVersionStringException: " + exception.getMessage());
getLogger().error("Got InvalidVersionStringException: " + exception.getMessage());
if (exception.getThrowable() != null) {
logger.error("Original stack trace:");
getLogger().error("Original stack trace:");
throw exception.getThrowable();
}
fail("Got InvalidVersionStringException");

View file

@ -21,12 +21,10 @@ package de.staropensource.sosengine.base.srctests.data.versioning;
import de.staropensource.sosengine.base.data.versioning.SemanticVersioningSystem;
import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException;
import de.staropensource.sosengine.unittests.UnitLogger;
import de.staropensource.sosengine.base.srctests.TestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@ -36,13 +34,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/
@SuppressWarnings({ "unused" })
@DisplayName("SemanticVersioningSystem")
public class SemanticVersioningSystemTest {
/**
* The unit logger for this instance.
*/
private static final UnitLogger logger = new UnitLogger(SemanticVersioningSystemTest.class);
private static final Logger log = LoggerFactory.getLogger(SemanticVersioningSystemTest.class);
public class SemanticVersioningSystemTest extends TestBase {
/**
* Tests the method {@code compare}.
*/
@ -63,14 +55,14 @@ public class SemanticVersioningSystemTest {
"1.1.0+5, 1.1.0+6, 2",
})
void testCompare(String a, String b, int expected) throws Throwable {
logger.testCall("testCompare", a, b, expected);
getLogger().testCall("testCompare", a, b, expected);
try {
assertEquals(expected, new SemanticVersioningSystem(a).compare(new SemanticVersioningSystem(b)));
} catch (InvalidVersionStringException exception) {
logger.error("Got InvalidVersionStringException: " + exception.getMessage());
getLogger().error("Got InvalidVersionStringException: " + exception.getMessage());
if (exception.getThrowable() != null) {
logger.error("Original stack trace:");
getLogger().error("Original stack trace:");
throw exception.getThrowable();
}
fail("Got InvalidVersionStringException");

View file

@ -22,7 +22,7 @@ package de.staropensource.sosengine.base.srctests.data.versioning;
import de.staropensource.sosengine.base.data.versioning.SemanticVersioningSystem;
import de.staropensource.sosengine.base.data.versioning.StarOpenSourceVersioningSystem;
import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException;
import de.staropensource.sosengine.unittests.UnitLogger;
import de.staropensource.sosengine.base.srctests.TestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
@ -35,12 +35,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/
@SuppressWarnings({ "unused" })
@DisplayName("StarOpenSourceVersioningSystem")
public class StarOpenSourceVersioningSystemTest {
/**
* The unit logger for this instance.
*/
private static final UnitLogger logger = new UnitLogger(StarOpenSourceVersioningSystemTest.class);
public class StarOpenSourceVersioningSystemTest extends TestBase {
/**
* Tests the method {@code compare}.
*/
@ -59,14 +54,14 @@ public class StarOpenSourceVersioningSystemTest {
"v9-beta5, v9-releasecandidate1, 2",
})
void testCompare(String a, String b, int expected) throws Throwable {
logger.testCall("testCompare", a, b, expected);
getLogger().testCall("testCompare", a, b, expected);
try {
assertEquals(expected, new StarOpenSourceVersioningSystem(a).compare(new StarOpenSourceVersioningSystem(b)));
} catch (InvalidVersionStringException exception) {
logger.error("Got InvalidVersionStringException: " + exception.getMessage());
getLogger().error("Got InvalidVersionStringException: " + exception.getMessage());
if (exception.getThrowable() != null) {
logger.error("Original stack trace:");
getLogger().error("Original stack trace:");
throw exception.getThrowable();
}
fail("Got InvalidVersionStringException");

View file

@ -21,12 +21,10 @@ package de.staropensource.sosengine.base.srctests.data.versioning;
import de.staropensource.sosengine.base.data.versioning.ThreeNumberVersioningSystem;
import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException;
import de.staropensource.sosengine.unittests.UnitLogger;
import de.staropensource.sosengine.base.srctests.TestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@ -36,13 +34,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/
@SuppressWarnings({ "unused" })
@DisplayName("ThreeNumberVersioningSystem")
public class ThreeNumberVersioningSystemTest {
/**
* The unit logger for this instance.
*/
private static final UnitLogger logger = new UnitLogger(ThreeNumberVersioningSystemTest.class);
private static final Logger log = LoggerFactory.getLogger(ThreeNumberVersioningSystemTest.class);
public class ThreeNumberVersioningSystemTest extends TestBase {
/**
* Tests the method {@code compare}.
*/
@ -54,14 +46,14 @@ public class ThreeNumberVersioningSystemTest {
"1.1.0, 1.1.1, 2",
})
void testCompare(String a, String b, int expected) throws Throwable {
logger.testCall("testCompare", a, b, expected);
getLogger().testCall("testCompare", a, b, expected);
try {
assertEquals(expected, new ThreeNumberVersioningSystem(a).compare(new ThreeNumberVersioningSystem(b)));
} catch (InvalidVersionStringException exception) {
logger.error("Got InvalidVersionStringException: " + exception.getMessage());
getLogger().error("Got InvalidVersionStringException: " + exception.getMessage());
if (exception.getThrowable() != null) {
logger.error("Original stack trace:");
getLogger().error("Original stack trace:");
throw exception.getThrowable();
}
fail("Got InvalidVersionStringException");

View file

@ -21,12 +21,10 @@ package de.staropensource.sosengine.base.srctests.data.versioning;
import de.staropensource.sosengine.base.data.versioning.TwoNumberVersioningSystem;
import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException;
import de.staropensource.sosengine.unittests.UnitLogger;
import de.staropensource.sosengine.base.srctests.TestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@ -36,13 +34,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/
@SuppressWarnings({ "unused" })
@DisplayName("TwoNumberVersioningSystem")
public class TwoNumberVersioningSystemTest {
/**
* The unit logger for this instance.
*/
private static final UnitLogger logger = new UnitLogger(TwoNumberVersioningSystemTest.class);
private static final Logger log = LoggerFactory.getLogger(TwoNumberVersioningSystemTest.class);
public class TwoNumberVersioningSystemTest extends TestBase {
/**
* Tests the method {@code compare}.
*/
@ -54,14 +46,14 @@ public class TwoNumberVersioningSystemTest {
"1.5, 2.0, 2",
})
void testCompare(String a, String b, int expected) throws Throwable {
logger.testCall("testCompare", a, b, expected);
getLogger().testCall("testCompare", a, b, expected);
try {
assertEquals(expected, new TwoNumberVersioningSystem(a).compare(new TwoNumberVersioningSystem(b)));
} catch (InvalidVersionStringException exception) {
logger.error("Got InvalidVersionStringException: " + exception.getMessage());
getLogger().error("Got InvalidVersionStringException: " + exception.getMessage());
if (exception.getThrowable() != null) {
logger.error("Original stack trace:");
getLogger().error("Original stack trace:");
throw exception.getThrowable();
}
fail("Got InvalidVersionStringException");

View file

@ -22,12 +22,10 @@ package de.staropensource.sosengine.base.srctests.utility;
import de.staropensource.sosengine.base.EngineConfiguration;
import de.staropensource.sosengine.base.annotations.EventListener;
import de.staropensource.sosengine.base.events.ThrowableCatchEvent;
import de.staropensource.sosengine.base.exceptions.UnexpectedThrowableException;
import de.staropensource.sosengine.base.exceptions.reflection.InvalidMethodException;
import de.staropensource.sosengine.base.reflection.Reflect;
import de.staropensource.sosengine.base.srctests.TestBase;
import de.staropensource.sosengine.base.utility.Math;
import de.staropensource.sosengine.base.utility.Miscellaneous;
import de.staropensource.sosengine.unittests.UnitLogger;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
@ -36,8 +34,6 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@ -50,12 +46,7 @@ import static org.junit.jupiter.api.Assertions.*;
*/
@SuppressWarnings("unused")
@DisplayName("Miscellaneous")
public class MiscellaneousTest {
/**
* The {@link UnitLogger} for this instance.
*/
private static final UnitLogger logger = new UnitLogger(MiscellaneousTest.class);
public class MiscellaneousTest extends TestBase {
/**
* Used for testing the method {@code executeSafely}.
*/
@ -65,7 +56,7 @@ public class MiscellaneousTest {
* Sets the {@link EngineConfiguration}#{@code instance} to {@code null} after each test.
*/
@AfterEach
void clearConfiguration() throws InvalidMethodException, UnexpectedThrowableException, InvocationTargetException {
void clearConfiguration() throws Exception {
// For method testExecuteSafely1()
Reflect.reflectOn(EngineConfiguration.class).getMethod("clearInstance").invoke();
}
@ -83,26 +74,11 @@ public class MiscellaneousTest {
"5819853, 10, 0005819853"
})
void testPadNumbers(int number, int length, String expected) {
logger.testCall("testPadNumbers", number, length, expected);
getLogger().testCall("testPadNumbers", number, length, expected);
String result = Math.padNumbers(number, length);
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
}
/**
* Tests the method {@code invokeGarbageCollector}.
*/
@Test
@DisplayName("invokeGarbageCollector")
void testInvokeGarbageCollector(){
logger.testCall("testInvokeGarbageCollector");
Object object = new Object();
WeakReference<Object> weakReference = new WeakReference<>(object);
object = null;
Miscellaneous.invokeGarbageCollector();
//noinspection ConstantValue // my god we know that it's very very likely true, that's what we're testing for here!
assertNull(object, "Garbage collector failed collecting nullified object");
}
/**
* Tests the method {@code measureExecutionTime}.
*/
@ -112,13 +88,13 @@ public class MiscellaneousTest {
100, 250, 500
})
void testMeasureExecutionTime(int sleepingDuration) {
logger.testCall("testMeasureExecutionTime", sleepingDuration);
getLogger().testCall("testMeasureExecutionTime", sleepingDuration);
long executionTime = Miscellaneous.measureExecutionTime(() -> {
try {
Thread.sleep(sleepingDuration);
} catch (InterruptedException e) {
logger.error("Sleep was interrupted, test may fail");
getLogger().error("Sleep was interrupted, test may fail");
}
});
@ -131,7 +107,7 @@ public class MiscellaneousTest {
@Test
@DisplayName("getMapValues")
void testGetMapValues() {
logger.testCall("testGetMapValues");
getLogger().testCall("testGetMapValues");
Map<String, String> testMap = new HashMap<>();
testMap.put("key1", "this is the first value");
@ -153,13 +129,11 @@ public class MiscellaneousTest {
@Test
@DisplayName("executeSafely (test 0)")
void testExecuteSafely0() {
logger.testCall("testExecuteSafely0");
getLogger().testCall("testExecuteSafely0");
throwableCaught = false;
Miscellaneous.executeSafely(() -> {
System.out.println("You can safely ignore this message (this comes from MiscellaneousTest#testExecuteSafely0)");
}, "MiscellaneousTest#testExecuteSafely0");
Miscellaneous.executeSafely(() -> System.out.println("You can safely ignore this message (this comes from MiscellaneousTest#testExecuteSafely0)"), "MiscellaneousTest#testExecuteSafely0");
assertFalse(throwableCaught, "Event was triggered");
}
@ -170,7 +144,7 @@ public class MiscellaneousTest {
@Test
@DisplayName("executeSafely (test 1)")
void testExecuteSafely1() {
logger.testCall("testExecuteSafely1");
getLogger().testCall("testExecuteSafely1");
throwableCaught = false;
@ -192,7 +166,7 @@ public class MiscellaneousTest {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
logger.error("Sleep was interrupted, test may fail");
getLogger().error("Sleep was interrupted, test may fail");
throw new RuntimeException(e);
}
@ -207,8 +181,7 @@ public class MiscellaneousTest {
*/
@EventListener(event = ThrowableCatchEvent.class)
public static void onCaughtThrowable(@NotNull Throwable throwable, @NotNull String identifier) {
logger.diag("ThrowableCatchEvent received");
getInstance().getLogger().diag("ThrowableCatchEvent received");
throwableCaught = true;
throw new RuntimeException("aaaaa");
}
}

View file

@ -20,20 +20,13 @@
package de.staropensource.sosengine.base.srctests.utility;
import de.staropensource.sosengine.base.classes.Placeholder;
import de.staropensource.sosengine.base.exceptions.UnexpectedThrowableException;
import de.staropensource.sosengine.base.exceptions.reflection.InvalidMethodException;
import de.staropensource.sosengine.base.exceptions.reflection.NoAccessException;
import de.staropensource.sosengine.base.reflection.Reflect;
import de.staropensource.sosengine.base.srctests.TestBase;
import de.staropensource.sosengine.base.utility.PlaceholderEngine;
import de.staropensource.sosengine.unittests.UnitLogger;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@ -44,28 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
*/
@SuppressWarnings("unused")
@DisplayName("PlaceholderEngine")
class PlaceholderEngineTest {
/**
* The {@link UnitLogger} for this instance.
*/
private static final UnitLogger logger = new UnitLogger(PlaceholderEngineTest.class);
/**
* Creates a new {@link PlaceholderEngine} instance before each test.
*/
@BeforeEach
void createInstance() {
new PlaceholderEngine();
}
/**
* Sets the {@link PlaceholderEngine}#{@code instance} to {@code null} after each test.
*/
@AfterEach
void clearInstance() throws InvalidMethodException, UnexpectedThrowableException, InvocationTargetException, NoAccessException {
Reflect.reflectOn(PlaceholderEngine.class).getMethod("clearInstance").invoke();
}
class PlaceholderEngineTest extends TestBase {
/**
* Tests the method {@code process}.
*/
@ -77,7 +49,7 @@ class PlaceholderEngineTest {
"This %status%!, This works!",
})
void testProcess(String text, String expected) {
logger.testCall("testProcess", text, expected);
getLogger().testCall("testProcess", text, expected);
List<@NotNull Placeholder> placeholders = new ArrayList<>();
placeholders.add(new Placeholder() {

View file

@ -19,8 +19,8 @@
package de.staropensource.sosengine.base.srctests.utility;
import de.staropensource.sosengine.base.srctests.TestBase;
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
import de.staropensource.sosengine.unittests.UnitLogger;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
@ -33,12 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* Tests the class {@link PropertyParser}.
*/
@DisplayName("PropertyParser")
class PropertyParserTest {
/**
* The {@link UnitLogger} for this instance.
*/
private static final UnitLogger logger = new UnitLogger(PropertyParserTest.class);
class PropertyParserTest extends TestBase {
/**
* Tests the method {@code getString}.
*/
@ -51,7 +46,7 @@ class PropertyParserTest {
"a.property.mightLookLikeThis, some value"
})
void testGetString(String propertyName, String propertyValue) {
logger.testCall("testGetString", propertyName, propertyValue);
getLogger().testCall("testGetString", propertyName, propertyValue);
Properties properties = new Properties();
properties.setProperty(propertyName, propertyValue);
@ -75,7 +70,7 @@ class PropertyParserTest {
"nah, no, false",
})
void testGetBoolean(String propertyName, String propertyValue, boolean expected) {
logger.testCall("testGetBoolean", propertyName, propertyValue, expected);
getLogger().testCall("testGetBoolean", propertyName, propertyValue, expected);
Properties properties = new Properties();
properties.setProperty(propertyName, propertyValue);
@ -99,7 +94,7 @@ class PropertyParserTest {
"he's a 1 but he likes 0s, 1, 1",
})
void testGetByte(String propertyName, String propertyValue, byte expected) {
logger.testCall("testGetByte", propertyName, propertyValue, expected);
getLogger().testCall("testGetByte", propertyName, propertyValue, expected);
Properties properties = new Properties();
properties.setProperty(propertyName, propertyValue);
@ -123,7 +118,7 @@ class PropertyParserTest {
"he's a 1 but he likes 0s, 1, 1",
})
void testGetShort(String propertyName, String propertyValue, short expected) {
logger.testCall("testGetShort", propertyName, propertyValue, expected);
getLogger().testCall("testGetShort", propertyName, propertyValue, expected);
Properties properties = new Properties();
properties.setProperty(propertyName, propertyValue);
@ -148,7 +143,7 @@ class PropertyParserTest {
"he's a 10 but he likes 69, 10, 10",
})
void testGetInteger(String propertyName, String propertyValue, int expected) {
logger.testCall("testGetInteger", propertyName, propertyValue, expected);
getLogger().testCall("testGetInteger", propertyName, propertyValue, expected);
Properties properties = new Properties();
properties.setProperty(propertyName, propertyValue);
@ -173,7 +168,7 @@ class PropertyParserTest {
"he's a 10 but he likes 69, 10, 10",
})
void testGetLong(String propertyName, String propertyValue, long expected) {
logger.testCall("testGetLong", propertyName, propertyValue, expected);
getLogger().testCall("testGetLong", propertyName, propertyValue, expected);
Properties properties = new Properties();
properties.setProperty(propertyName, propertyValue);
@ -199,7 +194,7 @@ class PropertyParserTest {
"he's a 10 but he likes 69, 10.69, 10.69",
})
void testGetFloat(String propertyName, String propertyValue, float expected) {
logger.testCall("testGetFloat", propertyName, propertyValue, expected);
getLogger().testCall("testGetFloat", propertyName, propertyValue, expected);
Properties properties = new Properties();
properties.setProperty(propertyName, propertyValue);
@ -223,7 +218,7 @@ class PropertyParserTest {
"he's a 10 but he likes 69, 10.69, 10.69",
})
void testGetDouble(String propertyName, String propertyValue, double expected) {
logger.testCall("testGetDouble", propertyName, propertyValue, expected);
getLogger().testCall("testGetDouble", propertyName, propertyValue, expected);
Properties properties = new Properties();
properties.setProperty(propertyName, propertyValue);

View file

@ -19,8 +19,8 @@
package de.staropensource.sosengine.base.srctests.utility;
import de.staropensource.sosengine.base.srctests.TestBase;
import de.staropensource.sosengine.base.utility.parser.StackTraceParser;
import de.staropensource.sosengine.unittests.UnitLogger;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
@ -32,12 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* Tests the class {@link StackTraceParser}.
*/
@DisplayName("StackTraceParser")
class StackTraceParserTest {
/**
* The {@link UnitLogger} for this instance.
*/
private static final UnitLogger logger = new UnitLogger(StackTraceParserTest.class);
class StackTraceParserTest extends TestBase {
/**
* Tests the method {@code getHeader}.
*/
@ -49,7 +44,7 @@ class StackTraceParserTest {
"Some description here..."
})
void testGetHeader(@NotNull String message) {
logger.testCall("testGetHeader", message);
getLogger().testCall("testGetHeader", message);
String output;
if (message.isEmpty())

View file

@ -87,6 +87,11 @@ javadoc {
// Unit testing configuration
test {
useJUnitPlatform()
setMaxParallelForks(project.hasProperty("jobs") ? Integer.parseInt((String) project.property("jobs")) : 8)
setForkEvery(1)
setFailFast(true)
testLogging {
events("passed", "skipped", "failed")
}

View file

@ -122,6 +122,11 @@ javadoc {
// Unit testing configuration
test {
useJUnitPlatform()
setMaxParallelForks(project.hasProperty("jobs") ? Integer.parseInt((String) project.property("jobs")) : 8)
setForkEvery(1)
setFailFast(true)
testLogging {
events("passed", "skipped", "failed")
}

View file

@ -127,6 +127,11 @@ javadoc {
// Unit testing configuration
test {
useJUnitPlatform()
setMaxParallelForks(project.hasProperty("jobs") ? Integer.parseInt((String) project.property("jobs")) : 8)
setForkEvery(1)
setFailFast(true)
testLogging {
events("passed", "skipped", "failed")
}

View file

@ -124,6 +124,11 @@ javadoc {
// Unit testing configuration
test {
useJUnitPlatform()
setMaxParallelForks(project.hasProperty("jobs") ? Integer.parseInt((String) project.property("jobs")) : 8)
setForkEvery(1)
setFailFast(true)
testLogging {
events("passed", "skipped", "failed")
}