From 2392aa79872fa38e4321ac1410be1c1155a6bfea Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Mon, 29 Jul 2024 18:30:39 -0400 Subject: Update Notifications --- .../hysky/skyblocker/UpdateNotificationsTest.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/test/java/de/hysky/skyblocker/UpdateNotificationsTest.java (limited to 'src/test/java') diff --git a/src/test/java/de/hysky/skyblocker/UpdateNotificationsTest.java b/src/test/java/de/hysky/skyblocker/UpdateNotificationsTest.java new file mode 100644 index 00000000..751ab570 --- /dev/null +++ b/src/test/java/de/hysky/skyblocker/UpdateNotificationsTest.java @@ -0,0 +1,67 @@ +package de.hysky.skyblocker; + +import java.util.Comparator; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.JavaOps; + +import net.fabricmc.loader.api.SemanticVersion; +import net.fabricmc.loader.api.Version; +import net.minecraft.Bootstrap; +import net.minecraft.SharedConstants; + +public class UpdateNotificationsTest { + private final Comparator COMPARATOR = UpdateNotifications.COMPARATOR; + private final Codec SEM_VER_CODEC = UpdateNotifications.SEM_VER_CODEC; + private final SemanticVersion LATEST_VERSION = SEM_VER_CODEC.parse(JavaOps.INSTANCE, "1.22.0+1.21").getOrThrow(); + + @BeforeAll + public static void setupEnvironment() { + SharedConstants.createGameVersion(); + Bootstrap.initialize(); + } + + @Test + void testLatestAgainstRegular() { + SemanticVersion regular = SEM_VER_CODEC.parse(JavaOps.INSTANCE, "1.21.1+1.21").getOrThrow(); + + //Requires that the latest be newer than this normal release version + Assertions.assertTrue(COMPARATOR.compare(LATEST_VERSION, regular) > 0); + } + + @Test + void testLatestAgainstBeta() { + SemanticVersion beta = SEM_VER_CODEC.parse(JavaOps.INSTANCE, "1.22.0-beta.1+1.21").getOrThrow(); + + //Requires that the latest be newer than the beta + Assertions.assertTrue(COMPARATOR.compare(LATEST_VERSION, beta) > 0); + } + + @Test + void testLatestAgainstAlpha() { + SemanticVersion alpha = SEM_VER_CODEC.parse(JavaOps.INSTANCE, "1.22.0-alpha.1+1.21").getOrThrow(); + + //Requires that the latest be newer than the alpha + Assertions.assertTrue(COMPARATOR.compare(LATEST_VERSION, alpha) > 0); + } + + @Test + void testLatestAgainstOldAlpha() { + SemanticVersion oldAlpha = SEM_VER_CODEC.parse(JavaOps.INSTANCE, "1.21.1-alpha-pr-888-afc81df+1.21").getOrThrow(); + + //Requires the alpha is older than the latest + Assertions.assertEquals(COMPARATOR.compare(oldAlpha, LATEST_VERSION), -1); + } + + @Test + void testThatTheCurrentAlphaAgainstLatestShouldBeDiscarded() { + SemanticVersion currentAlpha = SEM_VER_CODEC.parse(JavaOps.INSTANCE, "1.22.0-alpha-pr-908-fe7d89a+1.21").getOrThrow(); + + //Requires that the current alpha be discarded against the latest version + Assertions.assertTrue(UpdateNotifications.shouldDiscard(currentAlpha, LATEST_VERSION)); + } +} -- cgit