diff --git a/build.gradle.kts b/build.gradle.kts index 83d9975..56a019b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,6 +26,7 @@ dependencies { testImplementation(libs.cyano) testImplementation(libs.aves) testImplementation(libs.junit.api) + testImplementation(libs.junit.params) testImplementation(libs.junit.platform.launcher) testRuntimeOnly(libs.junit.engine) } diff --git a/settings.gradle.kts b/settings.gradle.kts index 8e73c7f..7107c75 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -31,6 +31,7 @@ dependencyResolutionManagement { library("junit.api", "org.junit.jupiter", "junit-jupiter-api").withoutVersion() library("junit.engine", "org.junit.jupiter", "junit-jupiter-engine").withoutVersion() + library("junit.params", "org.junit.jupiter", "junit-jupiter-params").withoutVersion() library("junit.platform.launcher", "org.junit.platform", "junit-platform-launcher").withoutVersion() library("jetbrains.annotation", "org.jetbrains", "annotations").withoutVersion() } diff --git a/src/main/java/net/onelitefeather/guira/category/BasicCategory.java b/src/main/java/net/onelitefeather/guira/category/BasicCategory.java new file mode 100644 index 0000000..46f98c4 --- /dev/null +++ b/src/main/java/net/onelitefeather/guira/category/BasicCategory.java @@ -0,0 +1,25 @@ +package net.onelitefeather.guira.category; + +import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.format.TextColor; +import net.minestom.server.item.Material; + +/** + * Implementation of {@link Category} that provides basic information about a category. + * + * @param key of the category + * @param displayName of the category + * @param material of the category + * @param color of the category + * @author theEvilReaper + * @version 1.0.0 + * @since 0.10.0 + */ +public record BasicCategory( + Key key, + String displayName, + Material material, + TextColor color +) implements Category { + +} diff --git a/src/main/java/net/onelitefeather/guira/category/Category.java b/src/main/java/net/onelitefeather/guira/category/Category.java new file mode 100644 index 0000000..6083fea --- /dev/null +++ b/src/main/java/net/onelitefeather/guira/category/Category.java @@ -0,0 +1,43 @@ +package net.onelitefeather.guira.category; + +import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.format.TextColor; +import net.minestom.server.item.Material; + +/** + * Defines a category that can be used to categorize setup items. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 0.10.0 + */ +public interface Category { + + /** + * Returns the key of the category. + * + * @return the key + */ + Key key(); + + /** + * Returns the display name of the category. + * + * @return the display name + */ + String displayName(); + + /** + * Returns the material associated with the category. + * + * @return the material + */ + Material material(); + + /** + * Returns the color associated with the category. + * + * @return the color + */ + TextColor color(); +} diff --git a/src/main/java/net/onelitefeather/guira/category/SetupCategories.java b/src/main/java/net/onelitefeather/guira/category/SetupCategories.java new file mode 100644 index 0000000..4d88021 --- /dev/null +++ b/src/main/java/net/onelitefeather/guira/category/SetupCategories.java @@ -0,0 +1,28 @@ +package net.onelitefeather.guira.category; + +import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.format.NamedTextColor; +import net.minestom.server.item.Material; + +/** + * Helper class for providing predefined {@link Category} instances. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 0.10.0 + */ +public final class SetupCategories { + + private static final String NAMESPACE = "guira"; + + public static final Category NAME = + new BasicCategory(Key.key(NAMESPACE, "map_data/name"), "Name", Material.ACACIA_SIGN, NamedTextColor.YELLOW); + public static final Category AUTHOR = + new BasicCategory(Key.key(NAMESPACE, "map_data/author"), "Builder", Material.DARK_OAK_DOOR, NamedTextColor.AQUA); + public static final Category SPAWN = + new BasicCategory(Key.key(NAMESPACE, "map_data/spawn"), "Spawn", Material.COMPASS, NamedTextColor.RED); + + private SetupCategories() { + // Nothing to do here + } +} diff --git a/src/main/java/net/onelitefeather/guira/category/package-info.java b/src/main/java/net/onelitefeather/guira/category/package-info.java new file mode 100644 index 0000000..bbcb765 --- /dev/null +++ b/src/main/java/net/onelitefeather/guira/category/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.onelitefeather.guira.category; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/src/test/java/net/onelitefeather/guira/category/SetupCategoriesTest.java b/src/test/java/net/onelitefeather/guira/category/SetupCategoriesTest.java new file mode 100644 index 0000000..c736b62 --- /dev/null +++ b/src/test/java/net/onelitefeather/guira/category/SetupCategoriesTest.java @@ -0,0 +1,60 @@ +package net.onelitefeather.guira.category; + +import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.format.NamedTextColor; +import net.minestom.server.item.Material; +import org.junit.jupiter.api.Named; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class SetupCategoriesTest { + + private static final String NAMESPACE = "guira"; + + static Stream> categories() { + return Stream.of( + testCase("NAME", SetupCategories.NAME, "map_data/name", "Name", + Material.ACACIA_SIGN, NamedTextColor.YELLOW), + testCase("AUTHOR", SetupCategories.AUTHOR, "map_data/author", "Builder", + Material.DARK_OAK_DOOR, NamedTextColor.AQUA), + testCase("SPAWN", SetupCategories.SPAWN, "map_data/spawn", "Spawn", + Material.COMPASS, NamedTextColor.RED) + ); + } + + private static Named testCase( + String displayName, + Category category, + String keyValue, + String name, + Material material, + NamedTextColor color + ) { + return Named.of(displayName, new TestCase(category, Key.key(NAMESPACE, keyValue), name, material, color)); + } + + @ParameterizedTest + @MethodSource("categories") + void shouldProvideCorrectCategory(TestCase testCase) { + assertAll( + () -> assertEquals(testCase.key(), testCase.category().key()), + () -> assertEquals(testCase.name(), testCase.category().displayName()), + () -> assertEquals(testCase.material(), testCase.category().material()), + () -> assertEquals(testCase.color(), testCase.category().color()) + ); + } + + private record TestCase( + Category category, + Key key, + String name, + Material material, + NamedTextColor color + ) { + } +} \ No newline at end of file