Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/net/onelitefeather/guira/category/BasicCategory.java
Original file line number Diff line number Diff line change
@@ -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 {

}
43 changes: 43 additions & 0 deletions src/main/java/net/onelitefeather/guira/category/Category.java
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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 =

Check warning on line 18 in src/main/java/net/onelitefeather/guira/category/SetupCategories.java

View workflow job for this annotation

GitHub Actions / build / Build (macos-latest)

no comment

Check warning on line 18 in src/main/java/net/onelitefeather/guira/category/SetupCategories.java

View workflow job for this annotation

GitHub Actions / build / Build (ubuntu-latest)

no comment
new BasicCategory(Key.key(NAMESPACE, "map_data/name"), "Name", Material.ACACIA_SIGN, NamedTextColor.YELLOW);
public static final Category AUTHOR =

Check warning on line 20 in src/main/java/net/onelitefeather/guira/category/SetupCategories.java

View workflow job for this annotation

GitHub Actions / build / Build (macos-latest)

no comment

Check warning on line 20 in src/main/java/net/onelitefeather/guira/category/SetupCategories.java

View workflow job for this annotation

GitHub Actions / build / Build (ubuntu-latest)

no comment
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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@NotNullByDefault
package net.onelitefeather.guira.category;

Check warning on line 2 in src/main/java/net/onelitefeather/guira/category/package-info.java

View workflow job for this annotation

GitHub Actions / build / Build (macos-latest)

no comment

Check warning on line 2 in src/main/java/net/onelitefeather/guira/category/package-info.java

View workflow job for this annotation

GitHub Actions / build / Build (ubuntu-latest)

no comment

import org.jetbrains.annotations.NotNullByDefault;
Original file line number Diff line number Diff line change
@@ -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<Named<TestCase>> 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> 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
) {
}
}
Loading