diff --git a/base/build.gradle b/base/build.gradle index 1e94679..f00f0d4 100644 --- a/base/build.gradle +++ b/base/build.gradle @@ -47,6 +47,9 @@ dependencies { testImplementation(platform("org.junit:junit-bom:${dependencyJunit}")) testImplementation("org.junit.jupiter:junit-jupiter") testRuntimeOnly("org.junit.platform:junit-platform-launcher") + + // -> Project <- + testImplementation(project(":testing")) } // Fix delombok task diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/PrintStreamService.java b/base/src/main/java/de/staropensource/sosengine/base/logging/PrintStreamService.java index 0f26e67..025badf 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/logging/PrintStreamService.java +++ b/base/src/main/java/de/staropensource/sosengine/base/logging/PrintStreamService.java @@ -28,7 +28,7 @@ import java.io.PrintStream; import java.nio.charset.StandardCharsets; /** - * Contains {@link java.io.PrintStream}s for the standard + * Contains {@link PrintStream}s for the standard * output and standard error streams, which redirect * their input into the engine's logging infrastructure. * diff --git a/base/src/main/java/module-info.java b/base/src/main/java/module-info.java index ef9ffed..15d07b1 100644 --- a/base/src/main/java/module-info.java +++ b/base/src/main/java/module-info.java @@ -33,7 +33,6 @@ module sosengine.base { exports de.staropensource.sosengine.base.type.vector; exports de.staropensource.sosengine.base.utility; exports de.staropensource.sosengine.base.implementation.shortcode; - exports de.staropensource.sosengine.unittest; // Reflection access opens de.staropensource.sosengine.base; @@ -58,5 +57,4 @@ module sosengine.base { opens de.staropensource.sosengine.base.type.vector; opens de.staropensource.sosengine.base.utility; opens de.staropensource.sosengine.base.implementation.shortcode; - opens de.staropensource.sosengine.unittest; } 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 811e00e..38dad0b 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 @@ -21,6 +21,7 @@ package de.staropensource.sosengine.base.srctests; import de.staropensource.sosengine.base.EngineConfiguration; import de.staropensource.sosengine.base.type.logging.LogLevel; +import de.staropensource.sosengine.testing.TestBase; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/FourNumberVersioningSystemTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/FourNumberVersioningSystemTest.java index 53ad842..c3d3d0c 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/FourNumberVersioningSystemTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/FourNumberVersioningSystemTest.java @@ -21,7 +21,7 @@ package de.staropensource.sosengine.base.srctests.implementation.versioning; import de.staropensource.sosengine.base.implementation.versioning.FourNumberVersioningSystem; import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/OneNumberVersioningSystemTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/OneNumberVersioningSystemTest.java index 0f0628c..ee86308 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/OneNumberVersioningSystemTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/OneNumberVersioningSystemTest.java @@ -21,7 +21,7 @@ package de.staropensource.sosengine.base.srctests.implementation.versioning; import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException; import de.staropensource.sosengine.base.implementation.versioning.OneNumberVersioningSystem; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/SemanticVersioningSystemTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/SemanticVersioningSystemTest.java index 1ac0ddb..cce6d78 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/SemanticVersioningSystemTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/SemanticVersioningSystemTest.java @@ -21,7 +21,7 @@ package de.staropensource.sosengine.base.srctests.implementation.versioning; import de.staropensource.sosengine.base.implementation.versioning.SemanticVersioningSystem; import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/StarOpenSourceVersioningSystemTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/StarOpenSourceVersioningSystemTest.java index a9cfd69..d431afb 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/StarOpenSourceVersioningSystemTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/StarOpenSourceVersioningSystemTest.java @@ -21,7 +21,7 @@ package de.staropensource.sosengine.base.srctests.implementation.versioning; import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException; import de.staropensource.sosengine.base.implementation.versioning.StarOpenSourceVersioningSystem; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/ThreeNumberVersioningSystemTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/ThreeNumberVersioningSystemTest.java index 16987cc..7b0c1ca 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/ThreeNumberVersioningSystemTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/ThreeNumberVersioningSystemTest.java @@ -21,7 +21,7 @@ package de.staropensource.sosengine.base.srctests.implementation.versioning; import de.staropensource.sosengine.base.implementation.versioning.ThreeNumberVersioningSystem; import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/TwoNumberVersioningSystemTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/TwoNumberVersioningSystemTest.java index a6ded9c..64a98fd 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/TwoNumberVersioningSystemTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/implementation/versioning/TwoNumberVersioningSystemTest.java @@ -21,7 +21,7 @@ package de.staropensource.sosengine.base.srctests.implementation.versioning; import de.staropensource.sosengine.base.implementation.versioning.TwoNumberVersioningSystem; import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/DependencyResolverTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/DependencyResolverTest.java index a6a6c06..7d60b2e 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/DependencyResolverTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/DependencyResolverTest.java @@ -22,7 +22,7 @@ package de.staropensource.sosengine.base.srctests.utility; import de.staropensource.sosengine.base.exception.dependency.DependencyCycleException; import de.staropensource.sosengine.base.exception.dependency.UnmetDependenciesException; import de.staropensource.sosengine.base.implementation.versioning.OneNumberVersioningSystem; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import de.staropensource.sosengine.base.type.DependencyVector; import de.staropensource.sosengine.base.utility.DependencyResolver; import org.jetbrains.annotations.NotNull; @@ -289,9 +289,9 @@ class DependencyResolverTest extends TestBase { 1, 2, 3 }) void testResolveWithFailure(int layers) { - if (isRestricted()) return; + if (performMethodCalls("testResolveWithFailure", layers)) + return; - getLogger().testCall("testResolveWithFailure", layers); DependencyResolver resolver = new DependencyResolver(); Set<@NotNull DependencyVector> vectors = new HashSet<>(); Set<@NotNull String> dependencies = new HashSet<>(); @@ -512,9 +512,9 @@ class DependencyResolverTest extends TestBase { @Test @DisplayName("resolve (dependency cycle)") void testResolveDependencyCycle() { - if (isRestricted()) return; + if (performMethodCalls("testResolveDependencyCycle")) + return; - getLogger().testCall("testResolveDependencyCycle"); DependencyResolver resolver = new DependencyResolver(); Set<@NotNull DependencyVector> vectors = new HashSet<>(); Set<@NotNull String> dependencies = new HashSet<>(); diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/MiscellaneousTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/MiscellaneousTest.java index 734aa1c..627e17e 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/MiscellaneousTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/MiscellaneousTest.java @@ -22,7 +22,7 @@ package de.staropensource.sosengine.base.srctests.utility; import de.staropensource.sosengine.base.EngineConfiguration; import de.staropensource.sosengine.base.annotation.EventListener; import de.staropensource.sosengine.base.event.ThrowableCatchEvent; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import de.staropensource.sosengine.base.utility.Math; import de.staropensource.sosengine.base.utility.Miscellaneous; import org.jetbrains.annotations.NotNull; @@ -78,8 +78,8 @@ public class MiscellaneousTest extends TestBase { 100, 250, 500 }) void testMeasureExecutionTime(int sleepingDuration) { - if (isRestricted()) return; - getLogger().testCall("testMeasureExecutionTime", sleepingDuration); + if (performMethodCalls("testMeasureExecutionTime")) + return; long executionTime = Miscellaneous.measureExecutionTime(() -> { try { @@ -98,8 +98,8 @@ public class MiscellaneousTest extends TestBase { @Test @DisplayName("getMapValues") void testGetMapValues() { - if (isRestricted()) return; - getLogger().testCall("testGetMapValues"); + if (performMethodCalls("testGetMapValues")) + return; Map testMap = new HashMap<>(); testMap.put("key1", "this is the first value"); @@ -121,8 +121,8 @@ public class MiscellaneousTest extends TestBase { @Test @DisplayName("executeSafely (test 0)") void testExecuteSafely0() { - if (isRestricted()) return; - getLogger().testCall("testExecuteSafely0"); + if (performMethodCalls("testExecuteSafely0")) + return; throwableCaught = false; Miscellaneous.executeSafely(() -> System.out.println("You can safely ignore this message (this comes from MiscellaneousTest#testExecuteSafely0)"), "MiscellaneousTest#testExecuteSafely0"); @@ -136,8 +136,9 @@ public class MiscellaneousTest extends TestBase { @Test @DisplayName("executeSafely (test 1)") void testExecuteSafely1() { - if (isRestricted()) return; - getLogger().testCall("testExecuteSafely1"); + if (performMethodCalls("testExecuteSafely1")) + return; + throwableCaught = false; // Disable event optimization for instant results diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PlaceholderEngineTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PlaceholderEngineTest.java index 92ffc1b..4b3d046 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PlaceholderEngineTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PlaceholderEngineTest.java @@ -20,7 +20,7 @@ package de.staropensource.sosengine.base.srctests.utility; import de.staropensource.sosengine.base.implementable.Placeholder; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import de.staropensource.sosengine.base.utility.PlaceholderEngine; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.DisplayName; diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PropertiesReaderTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PropertiesReaderTest.java index c368fb2..898906c 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PropertiesReaderTest.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PropertiesReaderTest.java @@ -19,7 +19,7 @@ package de.staropensource.sosengine.base.srctests.utility; -import de.staropensource.sosengine.base.srctests.TestBase; +import de.staropensource.sosengine.testing.TestBase; import de.staropensource.sosengine.base.utility.PropertiesReader; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; @@ -71,8 +71,8 @@ class PropertiesReaderTest extends TestBase { "nah, no, false", }) void testGetBoolean(String propertyName, String propertyValue, boolean expected) { - if (isRestricted()) return; - getLogger().testCall("testGetBoolean", propertyName, propertyValue, expected); + if (performMethodCalls("testGetBoolean", propertyName, propertyValue, expected)) + return; Properties properties = new Properties(); properties.setProperty(propertyName, propertyValue); @@ -96,8 +96,8 @@ class PropertiesReaderTest extends TestBase { "he's a 1 but he likes 0s, 1, 1", }) void testGetByte(String propertyName, String propertyValue, byte expected) { - if (isRestricted()) return; - getLogger().testCall("testGetByte", propertyName, propertyValue, expected); + if (performMethodCalls("testGetByte", propertyName, propertyValue, expected)) + return; Properties properties = new Properties(); properties.setProperty(propertyName, propertyValue); @@ -121,8 +121,8 @@ class PropertiesReaderTest extends TestBase { "he's a 1 but he likes 0s, 1, 1", }) void testGetShort(String propertyName, String propertyValue, short expected) { - if (isRestricted()) return; - getLogger().testCall("testGetShort", propertyName, propertyValue, expected); + if (performMethodCalls("testGetShort", propertyName, propertyValue, expected)) + return; Properties properties = new Properties(); properties.setProperty(propertyName, propertyValue); @@ -147,8 +147,8 @@ class PropertiesReaderTest extends TestBase { "he's a 10 but he likes 69, 10, 10", }) void testGetInteger(String propertyName, String propertyValue, int expected) { - if (isRestricted()) return; - getLogger().testCall("testGetInteger", propertyName, propertyValue, expected); + if (performMethodCalls("testGetInteger", propertyName, propertyValue, expected)) + return; Properties properties = new Properties(); properties.setProperty(propertyName, propertyValue); @@ -173,8 +173,8 @@ class PropertiesReaderTest extends TestBase { "he's a 10 but he likes 69, 10, 10", }) void testGetLong(String propertyName, String propertyValue, long expected) { - if (isRestricted()) return; - getLogger().testCall("testGetLong", propertyName, propertyValue, expected); + if (performMethodCalls("testGetLong", propertyName, propertyValue, expected)) + return; Properties properties = new Properties(); properties.setProperty(propertyName, propertyValue); @@ -200,8 +200,8 @@ class PropertiesReaderTest extends TestBase { "he's a 10 but he likes 69, 10.69, 10.69", }) void testGetFloat(String propertyName, String propertyValue, float expected) { - if (isRestricted()) return; - getLogger().testCall("testGetFloat", propertyName, propertyValue, expected); + if (performMethodCalls("testGetFloat", propertyName, propertyValue, expected)) + return; Properties properties = new Properties(); properties.setProperty(propertyName, propertyValue); @@ -225,8 +225,8 @@ class PropertiesReaderTest extends TestBase { "he's a 10 but he likes 69, 10.69, 10.69", }) void testGetDouble(String propertyName, String propertyValue, double expected) { - if (isRestricted()) return; - getLogger().testCall("testGetDouble", propertyName, propertyValue, expected); + if (performMethodCalls("testGetDouble", propertyName, propertyValue, expected)) + return; Properties properties = new Properties(); properties.setProperty(propertyName, propertyValue); diff --git a/settings.gradle b/settings.gradle index c182b57..8e511c5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,6 +20,7 @@ rootProject.setName("sosengine") include("base") +include("testing") include("ansi") include("slf4j-compat") include("windowing") diff --git a/testing/build.gradle b/testing/build.gradle new file mode 100644 index 0000000..a55af24 --- /dev/null +++ b/testing/build.gradle @@ -0,0 +1,112 @@ +/* + * 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 . + */ +// Plugins +plugins { + id("java") + id("io.freefair.lombok") version("${pluginLombok}") + id("maven-publish") +} + +// Project dependencies +dependencies { + // Lombok + compileOnly("org.projectlombok:lombok:${dependencyLombok}") + annotationProcessor("org.projectlombok:lombok:${dependencyLombok}") + + // JetBrains Annotations + compileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}") + + // JUnit + implementation(platform("org.junit:junit-bom:${dependencyJunit}")) + implementation("org.junit.jupiter:junit-jupiter") + + // -> Project <- + implementation(project(":base")) +} + +// Fix delombok task +delombok.doFirst { + File target = file("${project.projectDir}/src/main/module-info.java") + File source = file("${project.projectDir}/src/main/java/module-info.java") + + target.delete() + source.renameTo(target) +} +delombok.doLast { + File target = file("${project.projectDir}/src/main/java/module-info.java") + File source = file("${project.projectDir}/src/main/module-info.java") + + target.delete() + source.renameTo(target) +} + +// Javadoc configuration +javadoc { + outputs.upToDateWhen { false } // Force task execution + dependsOn(delombok) // Make sure the source is delomboked first + + javadoc { + setClasspath(files(project.sourceSets.main.compileClasspath)) // Include dependencies + + options { + if (new File(projectDir, "src/main/javadoc/theme.css").exists()) + stylesheetFile = new File(projectDir, "src/main/javadoc/theme.css") // Theming is cool :3 + setMemberLevel(JavadocMemberLevel.PUBLIC) // Only display public stuff + setOverview("src/main/javadoc/overview.html") // We want a custom overview page to greet the visitor + setLocale("en_US") // 你好 + addStringOption("Xwerror", "-quiet") // Fail build on warning + + setJFlags([ + "-Duser.language=en_US" // See above + ]) + } + } +} + +// Include javadoc and source jar during publishing +java { + withJavadocJar() + withSourcesJar() +} + +// Build publishing configuration +// Note: You can safely ignore any errors or warnings thrown by your IDE here +publishing { + repositories { + maven { + name = "staropensource" + url = uri("https://mvn.staropensource.de/sosengine") + credentials(org.gradle.api.credentials.PasswordCredentials) + authentication { + //noinspection GroovyAssignabilityCheck + basic (BasicAuthentication) + } + } + } + publications { + //noinspection GroovyAssignabilityCheck + maven (MavenPublication) { + groupId = group + artifactId = project.getName() + version = version + //noinspection GroovyAssignabilityCheck + from components.java + } + } +} diff --git a/testing/gradle b/testing/gradle new file mode 120000 index 0000000..3337596 --- /dev/null +++ b/testing/gradle @@ -0,0 +1 @@ +../gradle \ No newline at end of file diff --git a/testing/gradlew b/testing/gradlew new file mode 120000 index 0000000..502f5a2 --- /dev/null +++ b/testing/gradlew @@ -0,0 +1 @@ +../gradlew \ No newline at end of file diff --git a/testing/gradlew.bat b/testing/gradlew.bat new file mode 120000 index 0000000..2840132 --- /dev/null +++ b/testing/gradlew.bat @@ -0,0 +1 @@ +../gradlew.bat \ No newline at end of file diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/TestBase.java b/testing/src/main/java/de/staropensource/sosengine/testing/TestBase.java similarity index 63% rename from base/src/test/java/de/staropensource/sosengine/base/srctests/TestBase.java rename to testing/src/main/java/de/staropensource/sosengine/testing/TestBase.java index dd7735f..f2597c9 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/TestBase.java +++ b/testing/src/main/java/de/staropensource/sosengine/testing/TestBase.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.staropensource.sosengine.base.srctests; +package de.staropensource.sosengine.testing; import de.staropensource.sosengine.base.Engine; import de.staropensource.sosengine.base.EngineConfiguration; @@ -25,58 +25,76 @@ import de.staropensource.sosengine.base.EngineInternals; import de.staropensource.sosengine.base.type.InternalAccessArea; import de.staropensource.sosengine.base.type.Tristate; import de.staropensource.sosengine.base.type.logging.LogLevel; -import de.staropensource.sosengine.unittest.UnitConfig; -import de.staropensource.sosengine.unittest.UnitLogger; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeEach; import java.util.*; /** - * A class implemented by all tests. + * The base class for all tests involving the StarOpenSource Engine. + *

+ * It handles unit testing configuration, engine startups and shutdowns, + * provides a logger instance (see {@link UnitLogger}) and much more. + * + * @since v1-alpha4 */ +@SuppressWarnings({ "JavadocDeclaration" }) public class TestBase { /** - * Instance of this test class. + * Contains the class instance. + * + * @since v1-alpha4 * -- GETTER -- - * Returns the instance of this test class. + * Returns the class instance. + * + * @return class instance + * @since v1-alpha4 */ @Getter private static TestBase instance; /** - * The unit logger for this test class. + * Contains the {@link UnitLogger} for this instance. + * + * @see UnitLogger + * @since v1-alpha4 * -- GETTER -- - * Returns the unit logger for this test class. + * Returns the {@link UnitLogger} for this instance. + * + * @return {@link UnitLogger} instance + * @see UnitLogger + * @since v1-alpha4 */ @Getter private final UnitLogger logger = new UnitLogger(getClass()); - /** - * Controls whether the engine should be automatically initialized or not. - */ - protected boolean doInitialization = true; - /** * Contains the test control mode. * Can be {@link Tristate#TRUE} for force-enable, {@link Tristate#FALSE} for force-disable or {@link Tristate#UNSET} for no test execution control. + * + * @since v1-alpha4 */ - protected @NotNull Tristate controlMode = Tristate.UNSET; + private @NotNull Tristate controlMode = Tristate.UNSET; /** * Contains all class names which should be enabled/disabled during testing. + * + * @since v1-alpha4 */ - protected @NotNull Set<@NotNull String> controlClasses = new HashSet<>(); + private final @NotNull Set<@NotNull String> controlClasses = new HashSet<>(); /** - * Determines whether to print a warning when a restricted class is instructed to run it's tests. + * Determines whether to issue a warning when a restricted test method is invoked. + * + * @since v1-alpha4 */ - protected boolean controlWarning; + private boolean controlWarning; /** * Constructs this class. + * + * @since v1-alpha4 */ public TestBase() { // JUnit for some reason recreates the test class every time a test method is called @@ -88,9 +106,11 @@ public class TestBase { } /** - * Reads the system properties and configures the environment appropriately. + * Configures the testing environment. + * + * @since v1-alpha4 */ - public void configureEnvironment() { + private void configureEnvironment() { for (Object propertyObject : System.getProperties().keySet()) { String property = (String) propertyObject; @@ -131,9 +151,58 @@ public class TestBase { } /** - * Allows specifying that only some tests are executed. + * Makes all the necessary calls your method likely executes upon being invoked. + * Those being: + * - {@link #isRestricted()} + * - {@link UnitLogger#testCall(String, Object...)} + * - {@link #initializeEngine()} + *

+ * Make sure return from your test method if this method returns {@code true}. + * + * @param initializeEngine if the engine should be initialized automatically + * @param method test method name + * @param arguments test method arguments + * @return {@code true} if the test method should return + * @since v1-alpha4 */ - protected final boolean isRestricted(boolean printWarning) { + protected final boolean performMethodCalls(boolean initializeEngine, @NotNull String method, @NotNull Object... arguments) { + if (isRestricted()) + return true; + + logger.testCall(method, arguments); + + if (initializeEngine) + initializeEngine(); + return false; + } + + /** + * Makes all the necessary calls your method likely executes upon being invoked. + * Those being: + * - {@link #isRestricted()} + * - {@link UnitLogger#testCall(String, Object...)} + * - {@link #initializeEngine()} + *

+ * Make sure return from your test method if this method returns {@code true}. + * + * @param method test method name + * @param arguments test method arguments + * @return {@code true} if the test method should return + * @see #performMethodCalls(boolean, String, Object...) + * @since v1-alpha4 + */ + protected final boolean performMethodCalls(@NotNull String method, @NotNull Object... arguments) { + return performMethodCalls(true, method, arguments); + } + + /** + * Checks whether the test class has been restricted. + * + * @param printWarning if a warning should be printed about the class restriction + * @return restricted status + * @since v1-alpha4 + */ + public final boolean isRestricted(boolean printWarning) { String className = getClass().getName().replace(getClass().getPackage().getName() + ".", ""); boolean allowed = controlMode == Tristate.TRUE && !controlClasses.contains(className) || controlMode == Tristate.FALSE && controlClasses.contains(className); @@ -145,33 +214,24 @@ public class TestBase { } /** - * Allows specifying that only some tests are executed. + * Checks whether the test class has been restricted. + * + * @return restricted status + * @since v1-alpha4 */ - protected final boolean isRestricted() { + public final boolean isRestricted() { return isRestricted(true); } /** - * Makes all the necessary calls your method likely executes upon being invoked. - * Those being: - * - {@link #isRestricted()} - * - {@link UnitLogger#testCall(String, Object...)} + * Initializes the engine. + *

+ * HIGHLY recommended over manually invoking {@link Engine#Engine()}. * - * Make sure return if this method returns {@code true}. + * @since v1-alpha4 */ - protected final boolean performMethodCalls(@NotNull String method, @NotNull Object... arguments) { - if (isRestricted()) - return true; - logger.testCall(method, arguments); - return false; - } - - /** - * Initializes the engine before running tests. - */ - @BeforeEach - void initializeEngine() { - if (Engine.getInstance() == null && doInitialization) { + public void initializeEngine() { + if (Engine.getInstance() == null) { logger.diag("Initializing engine"); System.getProperties().setProperty("sosengine.base.loggerLevel", "crash"); new Engine(); @@ -182,10 +242,14 @@ public class TestBase { } /** - * Shuts the engine down after running tests. + * Shuts the engine down safely. + *

+ * DO NOT CALL METHOD THIS MANUALLY. + * + * @since v1-alpha4 */ @AfterAll - static void shutdownEngine() { + protected static void shutdownEngine() { if (Engine.getInstance() != null) { System.getProperties().setProperty("sosengine.base.loggerLevel", "crash"); EngineConfiguration.getInstance().loadConfiguration(); diff --git a/base/src/main/java/de/staropensource/sosengine/unittest/UnitConfig.java b/testing/src/main/java/de/staropensource/sosengine/testing/UnitConfig.java similarity index 92% rename from base/src/main/java/de/staropensource/sosengine/unittest/UnitConfig.java rename to testing/src/main/java/de/staropensource/sosengine/testing/UnitConfig.java index a3d9b69..a9330e8 100644 --- a/base/src/main/java/de/staropensource/sosengine/unittest/UnitConfig.java +++ b/testing/src/main/java/de/staropensource/sosengine/testing/UnitConfig.java @@ -17,20 +17,20 @@ * along with this program. If not, see . */ -package de.staropensource.sosengine.unittest; +package de.staropensource.sosengine.testing; import de.staropensource.sosengine.base.type.logging.LogLevel; /** * Static configuration for unit test classes. * - * @since v1-alpha0 + * @since v1-alpha4 */ public class UnitConfig { /** * Constructs this class. * - * @since v1-alpha0 + * @since v1-alpha4 */ public UnitConfig() {} @@ -40,7 +40,7 @@ public class UnitConfig { * Note: The log level {@code SILENT_WARNING} has been repurposed for printing test calls. * * @see UnitLogger - * @since v1-alpha0 + * @since v1-alpha4 */ public static LogLevel loggerLevel = LogLevel.SILENT_WARNING; } diff --git a/base/src/main/java/de/staropensource/sosengine/unittest/UnitLogger.java b/testing/src/main/java/de/staropensource/sosengine/testing/UnitLogger.java similarity index 88% rename from base/src/main/java/de/staropensource/sosengine/unittest/UnitLogger.java rename to testing/src/main/java/de/staropensource/sosengine/testing/UnitLogger.java index 7ef1cdb..a679209 100644 --- a/base/src/main/java/de/staropensource/sosengine/unittest/UnitLogger.java +++ b/testing/src/main/java/de/staropensource/sosengine/testing/UnitLogger.java @@ -17,9 +17,8 @@ * along with this program. If not, see . */ -package de.staropensource.sosengine.unittest; +package de.staropensource.sosengine.testing; -import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.type.logging.LogLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,29 +30,29 @@ import org.jetbrains.annotations.Nullable; */ public class UnitLogger { /** - * The parent class, similar to {@link LoggerInstance}. + * The parent class this instance belongs to. * - * @since v1-alpha0 + * @since v1-alpha4 */ private final Class clazz; /** * Creates a new unit logger. * - * @param clazz parent class, similar to {@link LoggerInstance} - * @since v1-alpha0 + * @param clazz parent class + * @since v1-alpha4 */ public UnitLogger(Class clazz) { this.clazz = clazz; } /** - * Prints a log message. + * Processes and prints a log message. * * @param level level * @param message message * @param additionalStuff additional arguments - * @since v1-alpha0 + * @since v1-alpha4 */ private void log(@NotNull LogLevel level, @NotNull String message, @Nullable Object... additionalStuff) { String messageSingle = message; @@ -99,7 +98,7 @@ public class UnitLogger { * Prints a diagnostic message. * * @param message message - * @since v1-alpha0 + * @since v1-alpha4 */ public void diag(@NotNull String message) { log(LogLevel.DIAGNOSTIC, message); @@ -109,7 +108,7 @@ public class UnitLogger { * Prints a verbose message. * * @param message message - * @since v1-alpha0 + * @since v1-alpha4 */ public void verb(@NotNull String message) { log(LogLevel.VERBOSE, message); @@ -120,17 +119,17 @@ public class UnitLogger { * * @param methodName name of the test method * @param methodArgs arguments of the test method - * @since v1-alpha0 + * @since v1-alpha4 */ public void testCall(@NotNull String methodName, @Nullable Object... methodArgs) { log(LogLevel.SILENT_WARNING, methodName, methodArgs); } /** - * Prints a informational message. + * Prints an informational message. * * @param message message - * @since v1-alpha0 + * @since v1-alpha4 */ public void info(@NotNull String message) { log(LogLevel.INFORMATIONAL, message); @@ -140,17 +139,17 @@ public class UnitLogger { * Prints a warning message. * * @param message message - * @since v1-alpha0 + * @since v1-alpha4 */ public void warn(@NotNull String message) { log(LogLevel.WARNING, message); } /** - * Prints a error message. + * Prints an error message. * * @param message message - * @since v1-alpha0 + * @since v1-alpha4 */ public void error(@NotNull String message) { log(LogLevel.ERROR, message); diff --git a/base/src/main/java/de/staropensource/sosengine/unittest/package-info.java b/testing/src/main/java/de/staropensource/sosengine/testing/package-info.java similarity index 81% rename from base/src/main/java/de/staropensource/sosengine/unittest/package-info.java rename to testing/src/main/java/de/staropensource/sosengine/testing/package-info.java index b28c042..7911dcb 100644 --- a/base/src/main/java/de/staropensource/sosengine/unittest/package-info.java +++ b/testing/src/main/java/de/staropensource/sosengine/testing/package-info.java @@ -18,9 +18,10 @@ */ /** - * Classes targeted at unit tests. - * They aim at simplifying certain aspects of unit testing. + * Contains the code required for writing tests + * fast and efficiently in conjunction with the + * StarOpenSource Engine. * - * @since v1-alpha0 + * @since v1-alpha4 */ -package de.staropensource.sosengine.unittest; +package de.staropensource.sosengine.testing; diff --git a/testing/src/main/java/module-info.java b/testing/src/main/java/module-info.java new file mode 100644 index 0000000..c8d4255 --- /dev/null +++ b/testing/src/main/java/module-info.java @@ -0,0 +1,20 @@ +/** + * StarOpenSource Engine testing tools. + * + * @since v1-alpha4 + */ +module sosengine.testing { + // Dependencies + // -> Subsystems + requires transitive sosengine.base; + // -> Libraries + requires transitive static lombok; + requires transitive org.jetbrains.annotations; + requires org.junit.jupiter.api; + + // API access + exports de.staropensource.sosengine.testing; + + // Reflection access + opens de.staropensource.sosengine.testing; +}