From 6785ec64d3d185dbcd833882a31c771a7744d697 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 1 Sep 2024 21:33:38 +0200 Subject: [PATCH] Add TestBase#performMethodCalls method --- .../base/srctests/EngineConfigurationTest.java | 4 ++-- .../sosengine/base/srctests/TestBase.java | 17 ++++++++++++++++- .../FourNumberVersioningSystemTest.java | 4 ++-- .../OneNumberVersioningSystemTest.java | 4 ++-- .../SemanticVersioningSystemTest.java | 4 ++-- .../StarOpenSourceVersioningSystemTest.java | 4 ++-- .../ThreeNumberVersioningSystemTest.java | 4 ++-- .../TwoNumberVersioningSystemTest.java | 4 ++-- .../utility/DependencyResolverTest.java | 4 ++-- .../srctests/utility/MiscellaneousTest.java | 4 ++-- .../srctests/utility/PlaceholderEngineTest.java | 4 ++-- .../srctests/utility/PropertiesReaderTest.java | 4 ++-- 12 files changed, 38 insertions(+), 23 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 467276f7f..811e00ea2 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 @@ -42,8 +42,8 @@ class EngineConfigurationTest extends TestBase { @Test @DisplayName("Method loadConfiguration") void testLoadConfiguration() { - if (isRestricted()) return; - getLogger().testCall("testLoadConfiguration"); + if (performMethodCalls("testLoadConfiguration")) + return; Map<@NotNull String, @NotNull Object[]> settings = new HashMap<>(); Map<@NotNull String, @NotNull Object> defaultValues = new HashMap<>(); diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/TestBase.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/TestBase.java index a9eb37acc..dd7735fd5 100644 --- a/base/src/test/java/de/staropensource/sosengine/base/srctests/TestBase.java +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/TestBase.java @@ -150,7 +150,22 @@ public class TestBase { protected 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...)} + * + * Make sure return if this method returns {@code true}. + */ + 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. */ 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 1b8bc7334..53ad8424b 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 @@ -49,8 +49,8 @@ public class FourNumberVersioningSystemTest extends TestBase { "1.1.0.0, 1.1.1.1, 2", }) void testCompare(String a, String b, int expected) throws Throwable { - if (isRestricted()) return; - getLogger().testCall("testCompare", a, b, expected); + if (performMethodCalls("testCompare", a, b, expected)) + return; try { assertEquals(expected, new FourNumberVersioningSystem(a).compare(new FourNumberVersioningSystem(b))); 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 777cb54b1..314394c5b 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 @@ -46,8 +46,8 @@ public class OneNumberVersioningSystemTest extends TestBase { "1, 2, 2", }) void testCompare(String a, String b, int expected) throws Throwable { - if (isRestricted()) return; - getLogger().testCall("testCompare", a, b, expected); + if (performMethodCalls("testCompare", a, b, expected)) + return; try { assertEquals(expected, new OneNumberVersioningSystem(a).compare(new OneNumberVersioningSystem(b))); 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 075ba0c01..1ac0ddbf3 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 @@ -54,8 +54,8 @@ public class SemanticVersioningSystemTest extends TestBase { "1.1.0+5, 1.1.0+6, 2", }) void testCompare(String a, String b, int expected) throws Throwable { - if (isRestricted()) return; - getLogger().testCall("testCompare", a, b, expected); + if (performMethodCalls("testCompare", a, b, expected)) + return; try { assertEquals(expected, new SemanticVersioningSystem(a).compare(new SemanticVersioningSystem(b))); 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 b89635900..38050fdb1 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 @@ -53,8 +53,8 @@ public class StarOpenSourceVersioningSystemTest extends TestBase { "v9-beta5, v9-releasecandidate1, 2", }) void testCompare(String a, String b, int expected) throws Throwable { - if (isRestricted()) return; - getLogger().testCall("testCompare", a, b, expected); + if (performMethodCalls("testCompare", a, b, expected)) + return; try { assertEquals(expected, new StarOpenSourceVersioningSystem(a).compare(new StarOpenSourceVersioningSystem(b))); 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 47d01a3c1..16987cca8 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 @@ -45,8 +45,8 @@ public class ThreeNumberVersioningSystemTest extends TestBase { "1.1.0, 1.1.1, 2", }) void testCompare(String a, String b, int expected) throws Throwable { - if (isRestricted()) return; - getLogger().testCall("testCompare", a, b, expected); + if (performMethodCalls("testCompare", a, b, expected)) + return; try { assertEquals(expected, new ThreeNumberVersioningSystem(a).compare(new ThreeNumberVersioningSystem(b))); 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 0d85a6292..a6ded9c28 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 @@ -45,8 +45,8 @@ public class TwoNumberVersioningSystemTest extends TestBase { "1.5, 2.0, 2", }) void testCompare(String a, String b, int expected) throws Throwable { - if (isRestricted()) return; - getLogger().testCall("testCompare", a, b, expected); + if (performMethodCalls("testCompare", a, b, expected)) + return; try { assertEquals(expected, new TwoNumberVersioningSystem(a).compare(new TwoNumberVersioningSystem(b))); 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 0fdb70aea..e3d9041a9 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 @@ -46,9 +46,9 @@ class DependencyResolverTest extends TestBase { 0, 1, 2, 3 }) void testResolve(int layers) { - if (isRestricted()) return; + if (performMethodCalls("testResolve", layers)) + return; - getLogger().testCall("testResolve", layers); 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 65e5c595a..734aa1c69 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 @@ -62,9 +62,9 @@ public class MiscellaneousTest extends TestBase { "5819853, 10, 0005819853" }) void testPadNumbers(int number, int length, String expected) { - if (isRestricted()) return; + if (performMethodCalls("testPadNumbers", number, length, expected)) + return; - getLogger().testCall("testPadNumbers", number, length, expected); String result = Math.padNumbers(number, length); assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\""); } 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 14925182d..92ffc1ba5 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 @@ -48,8 +48,8 @@ class PlaceholderEngineTest extends TestBase { "This %status%!, This works!", }) void testProcess(String text, String expected) { - if (isRestricted()) return; - getLogger().testCall("testProcess", text, expected); + if (performMethodCalls("testProcess", text, expected)) + return; List<@NotNull Placeholder> placeholders = new ArrayList<>(); placeholders.add(new Placeholder() { 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 404580f4c..c368fb29a 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 @@ -46,8 +46,8 @@ class PropertiesReaderTest extends TestBase { "a.property.mightLookLikeThis, some value" }) void testGetString(String propertyName, String propertyValue) { - if (isRestricted()) return; - getLogger().testCall("testGetString", propertyName, propertyValue); + if (performMethodCalls("testGetString", propertyName, propertyValue)) + return; Properties properties = new Properties(); properties.setProperty(propertyName, propertyValue);