From 4402484d47609582427fc02cfd1cbe6457dbb271 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Tue, 9 Mar 2021 17:15:11 +0100 Subject: [PATCH] Fixed NoClassDefFoundError caused by latest Adventure-platform snapshot. (#4446) * Bumped adventure versions * Added Unit Test to ensure Adventure being set up correctly --- pom.xml | 10 +++--- .../gmail/nossr50/util/text/TextUtils.java | 5 ++- .../nossr50/util/text/TextUtilsTest.java | 33 +++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 src/test/java/com/gmail/nossr50/util/text/TextUtilsTest.java diff --git a/pom.xml b/pom.xml index 44adca431..bf8fbfddd 100755 --- a/pom.xml +++ b/pom.xml @@ -219,27 +219,27 @@ net.kyori adventure-text-serializer-gson - 4.5.1 + 4.7.0 net.kyori adventure-api - 4.5.1 + 4.7.0 net.kyori adventure-nbt - 4.5.1 + 4.7.0 net.kyori adventure-key - 4.5.1 + 4.7.0 net.kyori adventure-text-serializer-gson-legacy-impl - 4.5.1 + 4.7.0 net.kyori diff --git a/src/main/java/com/gmail/nossr50/util/text/TextUtils.java b/src/main/java/com/gmail/nossr50/util/text/TextUtils.java index b8d71500e..1d3c001d5 100644 --- a/src/main/java/com/gmail/nossr50/util/text/TextUtils.java +++ b/src/main/java/com/gmail/nossr50/util/text/TextUtils.java @@ -16,9 +16,12 @@ import org.jetbrains.annotations.Nullable; import java.util.List; public class TextUtils { - private static @Nullable LegacyComponentSerializer customLegacySerializer; + private TextUtils() { + // We don't want any instances of this class. + } + /** * Makes a single component from an array of components, can optionally add prefixes and suffixes to come before and after each component * @param componentsArray target array diff --git a/src/test/java/com/gmail/nossr50/util/text/TextUtilsTest.java b/src/test/java/com/gmail/nossr50/util/text/TextUtilsTest.java new file mode 100644 index 000000000..d46673168 --- /dev/null +++ b/src/test/java/com/gmail/nossr50/util/text/TextUtilsTest.java @@ -0,0 +1,33 @@ +package com.gmail.nossr50.util.text; + +import org.junit.Assert; +import org.junit.Test; + +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; + +/** + * This Unit Test checks if Adventure was set up correctly and works as expected. + * Normally we can rely on this to be the case. However sometimes our dependencies + * lack so far behind that things stop working correctly. + * This test ensures that basic functionality is guaranteed to work as we would expect. + * + * See https://github.com/mcMMO-Dev/mcMMO/pull/4446 + * + */ +public class TextUtilsTest { + + @Test + public void testColorizeText() { + String inputText = "&4This text should be red."; + + /* + * If this method raises an exception, we know Adventure is not set up correctly. + * This will also make the test fail and warn us about it. + */ + TextComponent component = TextUtils.colorizeText(inputText); + + Assert.assertEquals("Looks like Adventure is not working correctly.", + NamedTextColor.DARK_RED, component.color()); + } +}