From a9a27db4d1dab49816d38c31bc53fdb1865ef14e Mon Sep 17 00:00:00 2001 From: Osiris Team Date: Tue, 1 Oct 2024 19:43:17 +0200 Subject: [PATCH] test enhancements --- .../client/utils/ConsoleOutputCapturer.java | 8 +++- .../com/osiris/autoplug/client/UtilsTest.java | 6 +-- .../updater/DoCustomUpdateCheckTest.java | 29 ------------- .../tasks/updater/TestPluginUpdaters.java | 42 +++++++++++++++++++ 4 files changed, 52 insertions(+), 33 deletions(-) delete mode 100644 src/test/java/com/osiris/autoplug/client/tasks/updater/DoCustomUpdateCheckTest.java create mode 100644 src/test/java/com/osiris/autoplug/client/tasks/updater/TestPluginUpdaters.java diff --git a/src/main/java/com/osiris/autoplug/client/utils/ConsoleOutputCapturer.java b/src/main/java/com/osiris/autoplug/client/utils/ConsoleOutputCapturer.java index 362d9702..fed67b10 100644 --- a/src/main/java/com/osiris/autoplug/client/utils/ConsoleOutputCapturer.java +++ b/src/main/java/com/osiris/autoplug/client/utils/ConsoleOutputCapturer.java @@ -10,6 +10,7 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; public class ConsoleOutputCapturer { @@ -54,7 +55,12 @@ public void stop() { } public String getNewOutput() { - String newOutput = baos.toString(StandardCharsets.UTF_8); + String newOutput = null; + try { + newOutput = baos.toString(StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); // Never should be thrown + } baos.reset(); return newOutput; } diff --git a/src/test/java/com/osiris/autoplug/client/UtilsTest.java b/src/test/java/com/osiris/autoplug/client/UtilsTest.java index 84878de3..f176397d 100644 --- a/src/test/java/com/osiris/autoplug/client/UtilsTest.java +++ b/src/test/java/com/osiris/autoplug/client/UtilsTest.java @@ -28,11 +28,11 @@ public static MyBThreadManager createManagerWithDisplayer() throws JLineLinkExce } public static void init() throws IOException { - initDefaults(); initLogger(); + initDefaults(); } - public static void initDefaults() throws IOException { + private static void initDefaults() throws IOException { GD.VERSION = "AutoPlug-Client Test-Version"; GD.WORKING_DIR = new File(System.getProperty("user.dir") + "/test"); System.setProperty("user.dir", GD.WORKING_DIR.getAbsolutePath()); @@ -57,7 +57,7 @@ public static void initDefaults() throws IOException { if (!serverJar.exists()) serverJar.createNewFile(); } - public static void initLogger() { + private static void initLogger() { File logFile = new File(System.getProperty("user.dir") + "/logs/latest.log"); logFile.getParentFile().mkdirs(); new AL().start("AL", true, logFile, false, false); diff --git a/src/test/java/com/osiris/autoplug/client/tasks/updater/DoCustomUpdateCheckTest.java b/src/test/java/com/osiris/autoplug/client/tasks/updater/DoCustomUpdateCheckTest.java deleted file mode 100644 index 043d9e37..00000000 --- a/src/test/java/com/osiris/autoplug/client/tasks/updater/DoCustomUpdateCheckTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2024 Osiris-Team. - * All rights reserved. - * - * This software is copyrighted work, licensed under the terms - * of the MIT-License. Consult the "LICENSE" file for details. - */ - -package com.osiris.autoplug.client.tasks.updater; - -import com.osiris.autoplug.client.tasks.updater.plugins.MinecraftPlugin; -import com.osiris.autoplug.client.tasks.updater.search.CustomCheckURL; -import com.osiris.autoplug.client.tasks.updater.search.SearchResult; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; - - -class TestCustomUpdateCheck { - @Test - void test() { - MinecraftPlugin pl = new MinecraftPlugin("./plugins/", "Chunky", "0.0.0", "pop4959", 0, 0, null); - pl.customCheckURL = "https://api.modrinth.com/v2/project/chunky/version"; - pl.customDownloadURL = "https://cdn.modrinth.com/data/fALzjamp/versions/dPliWter/Chunky-1.4.16.jar"; - SearchResult sr = new CustomCheckURL().doCustomCheck(pl.customCheckURL, pl.getVersion()); - assertSame(SearchResult.Type.UPDATE_AVAILABLE, sr.type); - } -} diff --git a/src/test/java/com/osiris/autoplug/client/tasks/updater/TestPluginUpdaters.java b/src/test/java/com/osiris/autoplug/client/tasks/updater/TestPluginUpdaters.java new file mode 100644 index 00000000..59e87d44 --- /dev/null +++ b/src/test/java/com/osiris/autoplug/client/tasks/updater/TestPluginUpdaters.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Osiris-Team. + * All rights reserved. + * + * This software is copyrighted work, licensed under the terms + * of the MIT-License. Consult the "LICENSE" file for details. + */ + +package com.osiris.autoplug.client.tasks.updater; + +import com.osiris.autoplug.client.UtilsTest; +import com.osiris.autoplug.client.tasks.updater.mods.ModrinthAPI; +import com.osiris.autoplug.client.tasks.updater.plugins.MinecraftPlugin; +import com.osiris.autoplug.client.tasks.updater.search.CustomCheckURL; +import com.osiris.autoplug.client.tasks.updater.search.SearchResult; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertSame; + + +class TestPluginUpdaters { + @Test + void testCustom() throws IOException { + UtilsTest.init(); + MinecraftPlugin pl = new MinecraftPlugin("./plugins/", "Chunky", "0.0.0", "pop4959", 0, 0, null); + pl.customCheckURL = "https://api.modrinth.com/v2/project/chunky/version"; + pl.customDownloadURL = "https://cdn.modrinth.com/data/fALzjamp/versions/dPliWter/Chunky-1.4.16.jar"; + SearchResult sr = new CustomCheckURL().doCustomCheck(pl.customCheckURL, pl.getVersion()); + assertSame(SearchResult.Type.UPDATE_AVAILABLE, sr.type); + } + + @Test + void testModrinth() throws IOException { + UtilsTest.init(); + MinecraftPlugin pl = new MinecraftPlugin("./plugins/", "BMMarker", "0.0.0", "Miraculixx", 0, 0, null); + pl.modrinthId = "a8UoyV2h"; + SearchResult sr = new ModrinthAPI().searchUpdatePlugin(pl, "1.21.1"); + assertSame(SearchResult.Type.UPDATE_AVAILABLE, sr.type); + } +}