diff options
| author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2025-03-09 14:03:24 -0400 |
|---|---|---|
| committer | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2025-03-09 14:03:24 -0400 |
| commit | 04091c51ea285f592d73695a3e05aa391e8a9c7f (patch) | |
| tree | 3ea32107098cf12f462df183196101bbcd19aed8 /src | |
| parent | e42597644e9085d7b7cad41cdc88a1beb27388c2 (diff) | |
| download | Skyblocker-04091c51ea285f592d73695a3e05aa391e8a9c7f.tar.gz Skyblocker-04091c51ea285f592d73695a3e05aa391e8a9c7f.tar.bz2 Skyblocker-04091c51ea285f592d73695a3e05aa391e8a9c7f.zip | |
Fix class load order messing up unit tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/debug/Debug.java | 7 | ||||
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/Formatters.java | 15 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/main/java/de/hysky/skyblocker/debug/Debug.java b/src/main/java/de/hysky/skyblocker/debug/Debug.java index 03b49532..7bbacbb2 100644 --- a/src/main/java/de/hysky/skyblocker/debug/Debug.java +++ b/src/main/java/de/hysky/skyblocker/debug/Debug.java @@ -47,6 +47,13 @@ public class Debug { return DEBUG_ENABLED || FabricLoader.getInstance().isDevelopmentEnvironment() || SnapshotDebug.isInSnapshot(); } + /** + * Used for checking if unit tests are being run. + */ + public static boolean isTestEnvironment() { + return Boolean.getBoolean("IS_TEST_ENV"); + } + public static boolean webSocketDebug() { return SkyblockerConfigManager.get().debug.webSocketDebug; } diff --git a/src/main/java/de/hysky/skyblocker/utils/Formatters.java b/src/main/java/de/hysky/skyblocker/utils/Formatters.java index b51d4250..58b0abe5 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Formatters.java +++ b/src/main/java/de/hysky/skyblocker/utils/Formatters.java @@ -2,7 +2,7 @@ package de.hysky.skyblocker.utils; import ca.weblite.objc.Client; import com.ibm.icu.text.DateTimePatternGenerator; -import net.fabricmc.loader.api.FabricLoader; +import de.hysky.skyblocker.debug.Debug; import net.minecraft.client.MinecraftClient; import net.minecraft.util.Util; @@ -60,7 +60,7 @@ public class Formatters { * <p> * Examples: Thu Jan 30 2025 2:00:10 PM, Thu Jan 30 2025 14:00:10 */ - public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("E MMM d yyyy " + getTimeFormat(), Locale.US).withZone(ZoneId.systemDefault()); + public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("E MMM d yyyy " + getTimeFormat(), Locale.US).withZone(getTimeZone()); /** * Parses a number from a string. @@ -76,10 +76,17 @@ public class Formatters { } /** - * Returns the formatting for the time, always returns 12 hour in development environments for testing purposes. + * Returns the formatting for the time, always returns 12 hour in test environments. */ private static String getTimeFormat() { - return is12HourClock() || FabricLoader.getInstance().isDevelopmentEnvironment() ? "h:mm:ss a" : "HH:mm:ss"; + return is12HourClock() || Debug.isTestEnvironment() ? "h:mm:ss a" : "HH:mm:ss"; + } + + /** + * Returns the time zone to be used for date formatting, always returns UTC in test environments. + */ + private static ZoneId getTimeZone() { + return Debug.isTestEnvironment() ? ZoneId.of("UTC") : ZoneId.systemDefault(); } /** |
