From 42dd877b9737e5e89fabde5efc564733211a335c Mon Sep 17 00:00:00 2001 From: Glavo Date: Sat, 14 Jan 2023 01:48:38 +0800 Subject: [PATCH] Bump junit from 4 to 5 (#1997) --- .../hmcl/ui/GameCrashWindowTest.java | 6 +- .../util/AggregatedObservableListTest.java | 4 +- .../hmcl/game/CrashReportAnalyzerTest.java | 115 +++++++++--------- .../hmcl/game/JavaVersionConstraintTest.java | 7 +- .../CurseForgeRemoteModRepositoryTest.java | 11 +- .../org/jackhuang/hmcl/util/TaskTest.java | 53 ++++---- .../hmcl/util/VersionNumberTest.java | 27 ++-- .../hmcl/util/gson/DateTypeAdapterTest.java | 11 +- build.gradle.kts | 7 +- 9 files changed, 125 insertions(+), 116 deletions(-) diff --git a/HMCL/src/test/java/org/jackhuang/hmcl/ui/GameCrashWindowTest.java b/HMCL/src/test/java/org/jackhuang/hmcl/ui/GameCrashWindowTest.java index 2ea01d20e..016e790a6 100644 --- a/HMCL/src/test/java/org/jackhuang/hmcl/ui/GameCrashWindowTest.java +++ b/HMCL/src/test/java/org/jackhuang/hmcl/ui/GameCrashWindowTest.java @@ -26,8 +26,8 @@ import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.platform.JavaVersion; import org.jackhuang.hmcl.util.platform.ManagedProcess; import org.jackhuang.hmcl.util.platform.Platform; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.File; import java.nio.file.Paths; @@ -40,7 +40,7 @@ import static org.jackhuang.hmcl.util.Pair.pair; public class GameCrashWindowTest { @Test - @Ignore + @Disabled public void test() throws Exception { JavaFXLauncher.start(); diff --git a/HMCL/src/test/java/org/jackhuang/hmcl/util/AggregatedObservableListTest.java b/HMCL/src/test/java/org/jackhuang/hmcl/util/AggregatedObservableListTest.java index 44f349557..177c62ec0 100644 --- a/HMCL/src/test/java/org/jackhuang/hmcl/util/AggregatedObservableListTest.java +++ b/HMCL/src/test/java/org/jackhuang/hmcl/util/AggregatedObservableListTest.java @@ -2,9 +2,9 @@ package org.jackhuang.hmcl.util; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * Testing the AggregatedObservableList diff --git a/HMCLCore/src/test/java/org/jackhuang/hmcl/game/CrashReportAnalyzerTest.java b/HMCLCore/src/test/java/org/jackhuang/hmcl/game/CrashReportAnalyzerTest.java index 2c7c05d78..d082cbe52 100644 --- a/HMCLCore/src/test/java/org/jackhuang/hmcl/game/CrashReportAnalyzerTest.java +++ b/HMCLCore/src/test/java/org/jackhuang/hmcl/game/CrashReportAnalyzerTest.java @@ -20,13 +20,14 @@ package org.jackhuang.hmcl.game; import org.jackhuang.hmcl.util.Log4jLevel; import org.jackhuang.hmcl.util.Pair; import org.jackhuang.hmcl.util.io.IOUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStream; import java.util.*; +import static org.junit.jupiter.api.Assertions.*; + public class CrashReportAnalyzerTest { private String loadLog(String path) throws IOException { List> logs = new ArrayList<>(); @@ -39,7 +40,7 @@ public class CrashReportAnalyzerTest { private CrashReportAnalyzer.Result findResultByRule(List results, CrashReportAnalyzer.Rule rule) { CrashReportAnalyzer.Result r = results.stream().filter(result -> result.getRule() == rule).findFirst().orElse(null); - Assert.assertNotNull(r); + assertNotNull(r); return r; } @@ -62,7 +63,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/logs/mod_resolution.txt")), CrashReportAnalyzer.Rule.MOD_RESOLUTION); - Assert.assertEquals(("Errors were found!\n" + + assertEquals(("Errors were found!\n" + " - Mod test depends on mod {fabricloader @ [>=0.11.3]}, which is missing!\n" + " - Mod test depends on mod {fabric @ [*]}, which is missing!\n" + " - Mod test depends on mod {java @ [>=16]}, which is missing!\n").replaceAll("\\s+", ""), @@ -74,8 +75,8 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/logs/mod_resolution_collection.txt")), CrashReportAnalyzer.Rule.MOD_RESOLUTION_COLLECTION); - Assert.assertEquals("tabtps-fabric", result.getMatcher().group("sourcemod")); - Assert.assertEquals("{fabricloader @ [>=0.11.1]}", result.getMatcher().group("destmod")); + assertEquals("tabtps-fabric", result.getMatcher().group("sourcemod")); + assertEquals("{fabricloader @ [>=0.11.1]}", result.getMatcher().group("destmod")); } @Test @@ -83,7 +84,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/logs/too_old_java.txt")), CrashReportAnalyzer.Rule.TOO_OLD_JAVA); - Assert.assertEquals("60", result.getMatcher().group("expected")); + assertEquals("60", result.getMatcher().group("expected")); } @Test @@ -91,7 +92,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/too_old_java.txt")), CrashReportAnalyzer.Rule.TOO_OLD_JAVA); - Assert.assertEquals("52", result.getMatcher().group("expected")); + assertEquals("52", result.getMatcher().group("expected")); } @Test @@ -99,7 +100,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/too_old_java2.txt")), CrashReportAnalyzer.Rule.TOO_OLD_JAVA); - Assert.assertEquals("52", result.getMatcher().group("expected")); + assertEquals("52", result.getMatcher().group("expected")); } @Test @@ -107,7 +108,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/security.txt")), CrashReportAnalyzer.Rule.FILE_CHANGED); - Assert.assertEquals("assets/minecraft/texts/splashes.txt", result.getMatcher().group("file")); + assertEquals("assets/minecraft/texts/splashes.txt", result.getMatcher().group("file")); } @Test @@ -115,7 +116,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/no_class_def_found_error.txt")), CrashReportAnalyzer.Rule.NO_CLASS_DEF_FOUND_ERROR); - Assert.assertEquals("blk", result.getMatcher().group("class")); + assertEquals("blk", result.getMatcher().group("class")); } @Test @@ -123,7 +124,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/no_class_def_found_error2.txt")), CrashReportAnalyzer.Rule.NO_CLASS_DEF_FOUND_ERROR); - Assert.assertEquals("cer", result.getMatcher().group("class")); + assertEquals("cer", result.getMatcher().group("class")); } @Test @@ -131,7 +132,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/file_already_exists.txt")), CrashReportAnalyzer.Rule.FILE_ALREADY_EXISTS); - Assert.assertEquals( + assertEquals( "D:\\Games\\Minecraft\\Minecraft Longtimeusing\\.minecraft\\versions\\1.12.2-forge1.12.2-14.23.5.2775\\config\\pvpsettings.txt", result.getMatcher().group("file")); } @@ -141,8 +142,8 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/loader_exception_mod_crash.txt")), CrashReportAnalyzer.Rule.LOADING_CRASHED_FORGE); - Assert.assertEquals("Better PvP", result.getMatcher().group("name")); - Assert.assertEquals("xaerobetterpvp", result.getMatcher().group("id")); + assertEquals("Better PvP", result.getMatcher().group("name")); + assertEquals("xaerobetterpvp", result.getMatcher().group("id")); } @Test @@ -150,8 +151,8 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/loader_exception_mod_crash2.txt")), CrashReportAnalyzer.Rule.LOADING_CRASHED_FORGE); - Assert.assertEquals("Inventory Sort", result.getMatcher().group("name")); - Assert.assertEquals("invsort", result.getMatcher().group("id")); + assertEquals("Inventory Sort", result.getMatcher().group("name")); + assertEquals("invsort", result.getMatcher().group("id")); } @Test @@ -159,8 +160,8 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/loader_exception_mod_crash3.txt")), CrashReportAnalyzer.Rule.LOADING_CRASHED_FORGE); - Assert.assertEquals("SuperOres", result.getMatcher().group("name")); - Assert.assertEquals("superores", result.getMatcher().group("id")); + assertEquals("SuperOres", result.getMatcher().group("name")); + assertEquals("superores", result.getMatcher().group("id")); } @Test @@ -168,8 +169,8 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/loader_exception_mod_crash4.txt")), CrashReportAnalyzer.Rule.LOADING_CRASHED_FORGE); - Assert.assertEquals("Kathairis", result.getMatcher().group("name")); - Assert.assertEquals("kathairis", result.getMatcher().group("id")); + assertEquals("Kathairis", result.getMatcher().group("name")); + assertEquals("kathairis", result.getMatcher().group("id")); } @Test @@ -177,7 +178,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/loading_error_fabric.txt")), CrashReportAnalyzer.Rule.LOADING_CRASHED_FABRIC); - Assert.assertEquals("test", result.getMatcher().group("id")); + assertEquals("test", result.getMatcher().group("id")); } @Test @@ -220,7 +221,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/logs/bootstrap.txt")), CrashReportAnalyzer.Rule.BOOTSTRAP_FAILED); - Assert.assertEquals("prefab", result.getMatcher().group("id")); + assertEquals("prefab", result.getMatcher().group("id")); } @Test @@ -228,7 +229,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/logs/unsatisfied_link_error.txt")), CrashReportAnalyzer.Rule.UNSATISFIED_LINK_ERROR); - Assert.assertEquals("lwjgl.dll", result.getMatcher().group("name")); + assertEquals("lwjgl.dll", result.getMatcher().group("name")); } @Test @@ -257,8 +258,8 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/config.txt")), CrashReportAnalyzer.Rule.CONFIG); - Assert.assertEquals("jumbofurnace", result.getMatcher().group("id")); - Assert.assertEquals("jumbofurnace-server.toml", result.getMatcher().group("file")); + assertEquals("jumbofurnace", result.getMatcher().group("id")); + assertEquals("jumbofurnace-server.toml", result.getMatcher().group("file")); } @Test @@ -266,7 +267,7 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/logs/fabric_warnings.txt")), CrashReportAnalyzer.Rule.FABRIC_WARNINGS); - Assert.assertEquals((" - Conflicting versions found for fabric-api-base: used 0.3.0+a02b446313, also found 0.3.0+a02b44633d, 0.3.0+a02b446318\n" + + assertEquals((" - Conflicting versions found for fabric-api-base: used 0.3.0+a02b446313, also found 0.3.0+a02b44633d, 0.3.0+a02b446318\n" + " - Conflicting versions found for fabric-rendering-data-attachment-v1: used 0.1.5+a02b446313, also found 0.1.5+a02b446318\n" + " - Conflicting versions found for fabric-rendering-fluids-v1: used 0.1.13+a02b446318, also found 0.1.13+a02b446313\n" + " - Conflicting versions found for fabric-lifecycle-events-v1: used 1.4.4+a02b44633d, also found 1.4.4+a02b446318\n" + @@ -282,8 +283,8 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/logs/fabric-mod-conflict.txt")), CrashReportAnalyzer.Rule.MOD_RESOLUTION_CONFLICT); - Assert.assertEquals("phosphor", result.getMatcher().group("sourcemod")); - Assert.assertEquals("{starlight @ [*]}", result.getMatcher().group("destmod")); + assertEquals("phosphor", result.getMatcher().group("sourcemod")); + assertEquals("{starlight @ [*]}", result.getMatcher().group("destmod")); } @Test @@ -291,8 +292,8 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/logs/fabric-mod-missing.txt")), CrashReportAnalyzer.Rule.MOD_RESOLUTION_MISSING); - Assert.assertEquals("pca", result.getMatcher().group("sourcemod")); - Assert.assertEquals("{fabric @ [>=0.39.2]}", result.getMatcher().group("destmod")); + assertEquals("pca", result.getMatcher().group("sourcemod")); + assertEquals("{fabric @ [>=0.39.2]}", result.getMatcher().group("destmod")); } @Test @@ -314,8 +315,8 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/logs/fabric-minecraft.txt")), CrashReportAnalyzer.Rule.MOD_RESOLUTION_MISSING_MINECRAFT); - Assert.assertEquals("fabric", result.getMatcher().group("mod")); - Assert.assertEquals("[~1.16.2-alpha.20.28.a]", result.getMatcher().group("version")); + assertEquals("fabric", result.getMatcher().group("mod")); + assertEquals("[~1.16.2-alpha.20.28.a]", result.getMatcher().group("version")); } @Test @@ -323,12 +324,12 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/mod/customnpc.txt")), CrashReportAnalyzer.Rule.ENTITY); - Assert.assertEquals("customnpcs.CustomNpc (noppes.npcs.entity.EntityCustomNpc)", + assertEquals("customnpcs.CustomNpc (noppes.npcs.entity.EntityCustomNpc)", result.getMatcher().group("type")); - Assert.assertEquals("99942.59, 4.00, 100000.98", + assertEquals("99942.59, 4.00, 100000.98", result.getMatcher().group("location")); - Assert.assertEquals( + assertEquals( new HashSet<>(Arrays.asList("npcs", "noppes")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/customnpc.txt"))); } @@ -338,103 +339,103 @@ public class CrashReportAnalyzerTest { CrashReportAnalyzer.Result result = findResultByRule( CrashReportAnalyzer.anaylze(loadLog("/crash-report/mod/tconstruct.txt")), CrashReportAnalyzer.Rule.BLOCK); - Assert.assertEquals("Block{tconstruct:seared_drain}[active=true,facing=north]", + assertEquals("Block{tconstruct:seared_drain}[active=true,facing=north]", result.getMatcher().group("type")); - Assert.assertEquals("World: (1370,92,-738), Chunk: (at 10,5,14 in 85,-47; contains blocks 1360,0,-752 to 1375,255,-737), Region: (2,-2; contains chunks 64,-64 to 95,-33, blocks 1024,0,-1024 to 1535,255,-513)", + assertEquals("World: (1370,92,-738), Chunk: (at 10,5,14 in 85,-47; contains blocks 1360,0,-752 to 1375,255,-737), Region: (2,-2; contains chunks 64,-64 to 95,-33, blocks 1024,0,-1024 to 1535,255,-513)", result.getMatcher().group("location")); - Assert.assertEquals( + assertEquals( new HashSet<>(Arrays.asList("tconstruct", "slimeknights", "smeltery")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/tconstruct.txt"))); } @Test public void bettersprinting() throws IOException { - Assert.assertEquals( + assertEquals( new HashSet<>(Arrays.asList("chylex", "bettersprinting")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/bettersprinting.txt"))); } @Test public void ic2() throws IOException { - Assert.assertEquals( - new HashSet<>(Collections.singletonList("ic2")), + assertEquals( + Collections.singleton("ic2"), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/ic2.txt"))); } @Test public void nei() throws IOException { - Assert.assertEquals( + assertEquals( new HashSet<>(Arrays.asList("nei", "codechicken", "guihook")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/nei.txt"))); } @Test public void netease() throws IOException { - Assert.assertEquals( + assertEquals( new HashSet<>(Arrays.asList("netease", "battergaming")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/netease.txt"))); } @Test public void flammpfeil() throws IOException { - Assert.assertEquals( + assertEquals( new HashSet<>(Arrays.asList("slashblade", "flammpfeil")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/flammpfeil.txt"))); } @Test public void creativemd() throws IOException { - Assert.assertEquals( + assertEquals( new HashSet<>(Arrays.asList("creativemd", "itemphysic")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/creativemd.txt"))); } @Test public void mapletree() throws IOException { - Assert.assertEquals( + assertEquals( new HashSet<>(Arrays.asList("MapleTree", "bamboo", "uraniummc", "ecru")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/mapletree.txt"))); } @Test public void thaumcraft() throws IOException { - Assert.assertEquals( - new HashSet<>(Collections.singletonList("thaumcraft")), + assertEquals( + Collections.singleton("thaumcraft"), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/thaumcraft.txt"))); } @Test public void shadersmodcore() throws IOException { - Assert.assertEquals( - new HashSet<>(Collections.singletonList("shadersmodcore")), + assertEquals( + Collections.singleton("shadersmodcore"), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/shadersmodcore.txt"))); } @Test public void twilightforest() throws IOException { - Assert.assertEquals( - new HashSet<>(Collections.singletonList("twilightforest")), + assertEquals( + Collections.singleton("twilightforest"), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/twilightforest.txt"))); } @Test public void optifine() throws IOException { - Assert.assertEquals( - new HashSet<>(Collections.singletonList("OptiFine")), + assertEquals( + Collections.singleton("OptiFine"), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/twilightforest_optifine_incompatibility.txt"))); } @Test public void wizardry() throws IOException { - Assert.assertEquals( + assertEquals( new HashSet<>(Arrays.asList("wizardry", "electroblob", "projectile")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/wizardry.txt"))); } @Test public void icycream() throws IOException { - Assert.assertEquals( + assertEquals( new HashSet<>(Collections.singletonList("icycream")), CrashReportAnalyzer.findKeywordsFromCrashReport(loadLog("/crash-report/mod/icycream.txt"))); } diff --git a/HMCLCore/src/test/java/org/jackhuang/hmcl/game/JavaVersionConstraintTest.java b/HMCLCore/src/test/java/org/jackhuang/hmcl/game/JavaVersionConstraintTest.java index 3acc77245..f1ed6f778 100644 --- a/HMCLCore/src/test/java/org/jackhuang/hmcl/game/JavaVersionConstraintTest.java +++ b/HMCLCore/src/test/java/org/jackhuang/hmcl/game/JavaVersionConstraintTest.java @@ -19,8 +19,9 @@ package org.jackhuang.hmcl.game; import org.apache.commons.lang3.Range; import org.jackhuang.hmcl.util.versioning.VersionNumber; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; public class JavaVersionConstraintTest { @@ -31,7 +32,7 @@ public class JavaVersionConstraintTest { null ); - Assert.assertEquals( + assertEquals( Range.between(VersionNumber.asVersion("16"), VersionNumber.asVersion(JavaVersionConstraint.MAX)), range.getMandatory()); } diff --git a/HMCLCore/src/test/java/org/jackhuang/hmcl/mod/curse/CurseForgeRemoteModRepositoryTest.java b/HMCLCore/src/test/java/org/jackhuang/hmcl/mod/curse/CurseForgeRemoteModRepositoryTest.java index bac0b016f..aa5477630 100644 --- a/HMCLCore/src/test/java/org/jackhuang/hmcl/mod/curse/CurseForgeRemoteModRepositoryTest.java +++ b/HMCLCore/src/test/java/org/jackhuang/hmcl/mod/curse/CurseForgeRemoteModRepositoryTest.java @@ -18,19 +18,20 @@ package org.jackhuang.hmcl.mod.curse; import org.jackhuang.hmcl.util.MurmurHash2; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; +import static org.junit.jupiter.api.Assertions.*; + public class CurseForgeRemoteModRepositoryTest { @Test - @Ignore + @Disabled public void testMurmurHash() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (InputStream is = Files.newInputStream(Paths.get("C:\\Users\\huang\\Downloads\\JustEnoughCalculation-1.16.5-3.8.5.jar"))) { @@ -48,6 +49,6 @@ public class CurseForgeRemoteModRepositoryTest { } long hash = Integer.toUnsignedLong(MurmurHash2.hash32(baos.toByteArray(), baos.size(), 1)); - Assert.assertEquals(hash, 3333498611L); + assertEquals(hash, 3333498611L); } } diff --git a/HMCLCore/src/test/java/org/jackhuang/hmcl/util/TaskTest.java b/HMCLCore/src/test/java/org/jackhuang/hmcl/util/TaskTest.java index d6a952959..0494d0764 100644 --- a/HMCLCore/src/test/java/org/jackhuang/hmcl/util/TaskTest.java +++ b/HMCLCore/src/test/java/org/jackhuang/hmcl/util/TaskTest.java @@ -22,17 +22,15 @@ import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.TaskExecutor; import org.jackhuang.hmcl.util.platform.JavaVersion; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import java.util.concurrent.CancellationException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import static org.junit.jupiter.api.Assertions.*; + public class TaskTest { /** * TaskExecutor will not catch error and will be thrown to global handler. @@ -41,13 +39,13 @@ public class TaskTest { public void expectErrorUncaught() { AtomicReference throwable = new AtomicReference<>(); Thread.setDefaultUncaughtExceptionHandler((t, e) -> throwable.set(e)); - Assert.assertFalse(Task.composeAsync(() -> Task.allOf( + assertFalse(Task.composeAsync(() -> Task.allOf( Task.allOf(Task.runAsync(() -> { throw new Error(); })) - )).whenComplete(Assert::assertNull).test()); + )).whenComplete(Assertions::assertNull).test()); - Assert.assertTrue("Error has not been thrown to uncaught exception handler", throwable.get() instanceof Error); + assertInstanceOf(Error.class, throwable.get(), "Error has not been thrown to uncaught exception handler"); } /** @@ -58,10 +56,10 @@ public class TaskTest { boolean result = Task.supplyAsync(() -> { throw new IllegalStateException(); }).whenComplete(exception -> { - Assert.assertTrue(exception instanceof IllegalStateException); + assertInstanceOf(IllegalStateException.class, exception); }).test(); - Assert.assertFalse("Task should fail at this case", result); + assertFalse(result, "Task should fail at this case"); } @Test @@ -73,8 +71,8 @@ public class TaskTest { bool.set(true); }).test(); - Assert.assertTrue("Task should success because withRunAsync will ignore previous exception", success); - Assert.assertTrue("withRunAsync should be executed", bool.get()); + assertTrue(success, "Task should success because withRunAsync will ignore previous exception"); + assertTrue(bool.get(), "withRunAsync should be executed"); } public void testThenAccept() { @@ -83,12 +81,12 @@ public class TaskTest { boolean result = Task.supplyAsync(JavaVersion::fromCurrentEnvironment) .thenAcceptAsync(Schedulers.javafx(), javaVersion -> { flag.set(true); - Assert.assertEquals(javaVersion, JavaVersion.fromCurrentEnvironment()); + assertEquals(javaVersion, JavaVersion.fromCurrentEnvironment()); }) .test(); - Assert.assertTrue("Task does not succeed", result); - Assert.assertTrue("ThenAccept has not been executed", flag.get()); + assertTrue(result, "Task does not succeed"); + assertTrue(flag.get(), "ThenAccept has not been executed"); } @Test @@ -103,7 +101,7 @@ public class TaskTest { }).thenRunAsync(() -> { System.out.println("No way!"); Thread.sleep(200); - Assert.fail("Cannot reach here"); + fail("Cannot reach here"); }); TaskExecutor executor = task.executor(); Lang.thread(() -> { @@ -114,14 +112,15 @@ public class TaskTest { System.out.println("Cancel"); executor.cancel(); } catch (InterruptedException e) { - Assume.assumeNoException(e); + fail(e); } }); - Assert.assertFalse("Task should fail because we have cancelled it", executor.test()); + assertFalse(executor.test(), "Task should fail because we have cancelled it"); Thread.sleep(3000); - Assert.assertTrue("CancellationException should not be recorded.", executor.getException() instanceof CancellationException); - Assert.assertTrue("CancellationException should not be recorded.", task.getException() instanceof CancellationException); - Assert.assertTrue("Thread.sleep cannot be interrupted", flag.get()); + + assertInstanceOf(CancellationException.class, executor.getException(), "CancellationException should not be recorded."); + assertInstanceOf(CancellationException.class, task.getException(), "CancellationException should not be recorded."); + assertTrue(flag.get(), "Thread.sleep cannot be interrupted"); } @Test @@ -148,7 +147,7 @@ public class TaskTest { } catch (InterruptedException e) { e.printStackTrace(); } - Assert.fail("Cannot reach here"); + fail("Cannot reach here"); })); }); Lang.thread(() -> { @@ -159,7 +158,7 @@ public class TaskTest { System.out.println("Cancel"); task.cancel(true); } catch (InterruptedException e) { - Assume.assumeNoException(e); + fail(e); } }); System.out.println("Start"); @@ -184,7 +183,7 @@ public class TaskTest { boolean result = task.test(); - Assert.assertFalse("Task should fail since ExecutorService is shut down and RejectedExecutionException should be thrown", result); - Assert.assertTrue("RejectedExecutionException should be recorded", task.getException() instanceof RejectedExecutionException); + assertFalse(result, "Task should fail since ExecutorService is shut down and RejectedExecutionException should be thrown"); + assertInstanceOf(RejectedExecutionException.class, task.getException(), "RejectedExecutionException should be recorded"); } } diff --git a/HMCLCore/src/test/java/org/jackhuang/hmcl/util/VersionNumberTest.java b/HMCLCore/src/test/java/org/jackhuang/hmcl/util/VersionNumberTest.java index 98c9ea3ca..b51ffbdc5 100644 --- a/HMCLCore/src/test/java/org/jackhuang/hmcl/util/VersionNumberTest.java +++ b/HMCLCore/src/test/java/org/jackhuang/hmcl/util/VersionNumberTest.java @@ -18,13 +18,14 @@ package org.jackhuang.hmcl.util; import org.jackhuang.hmcl.util.versioning.VersionNumber; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Comparator; import java.util.List; +import static org.junit.jupiter.api.Assertions.*; + public class VersionNumberTest { @Test @@ -32,19 +33,19 @@ public class VersionNumberTest { VersionNumber u, v; v = VersionNumber.asVersion("3.2.0.0"); - Assert.assertEquals("3.2", v.getCanonical()); + assertEquals("3.2", v.getCanonical()); v = VersionNumber.asVersion("3.2.0.0-5"); - Assert.assertEquals("3.2-5", v.getCanonical()); + assertEquals("3.2-5", v.getCanonical()); v = VersionNumber.asVersion("3.2.0.0-0"); - Assert.assertEquals("3.2", v.getCanonical()); + assertEquals("3.2", v.getCanonical()); v = VersionNumber.asVersion("3.2--------"); - Assert.assertEquals("3.2", v.getCanonical()); + assertEquals("3.2", v.getCanonical()); v = VersionNumber.asVersion("1.7.2$%%^@&snapshot-3.1.1"); - Assert.assertEquals("1.7.2$%%^@&snapshot-3.1.1", v.getCanonical()); + assertEquals("1.7.2$%%^@&snapshot-3.1.1", v.getCanonical()); } @Test @@ -53,27 +54,27 @@ public class VersionNumberTest { u = VersionNumber.asVersion("1.7.10forge1614_FTBInfinity"); v = VersionNumber.asVersion("1.12.2"); - Assert.assertTrue(u.compareTo(v) < 0); + assertTrue(u.compareTo(v) < 0); u = VersionNumber.asVersion("1.8.0_51"); v = VersionNumber.asVersion("1.8.0.51"); - Assert.assertTrue(u.compareTo(v) < 0); + assertTrue(u.compareTo(v) < 0); u = VersionNumber.asVersion("1.8.0_151"); v = VersionNumber.asVersion("1.8.0_77"); - Assert.assertTrue(u.compareTo(v) > 0); + assertTrue(u.compareTo(v) > 0); u = VersionNumber.asVersion("1.6.0_22"); v = VersionNumber.asVersion("1.8.0_11"); - Assert.assertTrue(u.compareTo(v) < 0); + assertTrue(u.compareTo(v) < 0); u = VersionNumber.asVersion("1.7.0_22"); v = VersionNumber.asVersion("1.7.99"); - Assert.assertTrue(u.compareTo(v) < 0); + assertTrue(u.compareTo(v) < 0); u = VersionNumber.asVersion("1.12.2-14.23.5.2760"); v = VersionNumber.asVersion("1.12.2-14.23.4.2739"); - Assert.assertTrue(u.compareTo(v) > 0); + assertTrue(u.compareTo(v) > 0); } @Test diff --git a/HMCLCore/src/test/java/org/jackhuang/hmcl/util/gson/DateTypeAdapterTest.java b/HMCLCore/src/test/java/org/jackhuang/hmcl/util/gson/DateTypeAdapterTest.java index 43564bab0..66f34c406 100644 --- a/HMCLCore/src/test/java/org/jackhuang/hmcl/util/gson/DateTypeAdapterTest.java +++ b/HMCLCore/src/test/java/org/jackhuang/hmcl/util/gson/DateTypeAdapterTest.java @@ -1,27 +1,28 @@ package org.jackhuang.hmcl.util.gson; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; +import static org.junit.jupiter.api.Assertions.*; + public class DateTypeAdapterTest { @Test public void parse() { - Assert.assertEquals( + assertEquals( LocalDateTime.of(2017, 6, 8, 4, 26, 33) .atOffset(ZoneOffset.UTC).toInstant(), DateTypeAdapter.deserializeToDate("2017-06-08T04:26:33+0000").toInstant()); - Assert.assertEquals( + assertEquals( LocalDateTime.of(2021, 1, 3, 0, 53, 34) .atOffset(ZoneOffset.UTC).toInstant(), DateTypeAdapter.deserializeToDate("2021-01-03T00:53:34+00:00").toInstant()); - Assert.assertEquals( + assertEquals( LocalDateTime.of(2021, 1, 3, 0, 53, 34) .atZone(ZoneId.systemDefault()).toInstant(), DateTypeAdapter.deserializeToDate("2021-01-03T00:53:34").toInstant()); diff --git a/build.gradle.kts b/build.gradle.kts index 8d6a9ce25..57bc8343d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,7 +38,12 @@ subprojects { } dependencies { - "testImplementation"("junit:junit:4.12") + "testImplementation"("org.junit.jupiter:junit-jupiter:5.9.1") + } + + tasks.withType { + useJUnitPlatform() + testLogging.showStandardStreams = true } configure {