mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45:51 +00:00
Added more Unit Tests
This commit is contained in:
parent
5b72faddc3
commit
3220a124aa
@ -45,6 +45,11 @@ public enum SlimefunTag implements Tag<Material> {
|
|||||||
*/
|
*/
|
||||||
ORES,
|
ORES,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All variants of torches, normal, soulfire and redstone.
|
||||||
|
*/
|
||||||
|
TORCHES,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All terracotta variants, does not include glazed terracotta.
|
* All terracotta variants, does not include glazed terracotta.
|
||||||
*/
|
*/
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"values" : [
|
"values" : [
|
||||||
"#minecraft:saplings",
|
"#minecraft:saplings",
|
||||||
"#minecraft:wooden_pressure_plates",
|
"#minecraft:wooden_pressure_plates",
|
||||||
|
"#slimefun:torches",
|
||||||
"minecraft:stone_pressure_plate",
|
"minecraft:stone_pressure_plate",
|
||||||
"minecraft:light_weighted_pressure_plate",
|
"minecraft:light_weighted_pressure_plate",
|
||||||
"minecraft:heavy_weighted_pressure_plate",
|
"minecraft:heavy_weighted_pressure_plate",
|
||||||
|
10
src/main/resources/tags/torches.json
Normal file
10
src/main/resources/tags/torches.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"values" : [
|
||||||
|
"minecraft:torch",
|
||||||
|
"minecraft:redstone_torch",
|
||||||
|
{
|
||||||
|
"id" : "minecraft:soul_torch",
|
||||||
|
"required" : false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.testing.tests.utils;
|
package io.github.thebusybiscuit.slimefun4.testing.tests.tags;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -55,6 +55,62 @@ class TestSlimefunTags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test SlimefunTag#isTagged()")
|
||||||
|
void testIsTagged() throws TagMisconfigurationException {
|
||||||
|
for (SlimefunTag tag : SlimefunTag.values()) {
|
||||||
|
tag.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Direct inclusion
|
||||||
|
Assertions.assertTrue(SlimefunTag.SENSITIVE_MATERIALS.isTagged(Material.CAKE));
|
||||||
|
|
||||||
|
// Inclusion through a Minecraft Tag
|
||||||
|
Assertions.assertTrue(SlimefunTag.SENSITIVE_MATERIALS.isTagged(Material.OAK_SAPLING));
|
||||||
|
|
||||||
|
// Inclusion through a Slimefun Tag
|
||||||
|
Assertions.assertTrue(SlimefunTag.SENSITIVE_MATERIALS.isTagged(Material.TORCH));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test SlimefunTag#toArray()")
|
||||||
|
void testToArray() throws TagMisconfigurationException {
|
||||||
|
for (SlimefunTag tag : SlimefunTag.values()) {
|
||||||
|
tag.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SlimefunTag tag : SlimefunTag.values()) {
|
||||||
|
Set<Material> values = tag.getValues();
|
||||||
|
Assertions.assertArrayEquals(values.toArray(new Material[0]), tag.toArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test SlimefunTag#getValues()")
|
||||||
|
void testGetValues() throws TagMisconfigurationException {
|
||||||
|
for (SlimefunTag tag : SlimefunTag.values()) {
|
||||||
|
tag.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SlimefunTag tag : SlimefunTag.values()) {
|
||||||
|
Set<Material> values = tag.getValues();
|
||||||
|
|
||||||
|
Assertions.assertFalse(values.isEmpty());
|
||||||
|
|
||||||
|
for (Material value : tag.getValues()) {
|
||||||
|
// All values of our tag must be tagged
|
||||||
|
Assertions.assertTrue(tag.isTagged(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Tag<Material> sub : tag.getSubTags()) {
|
||||||
|
for (Material value : sub.getValues()) {
|
||||||
|
// All values of sub tags should be tagged by our tag too
|
||||||
|
Assertions.assertTrue(tag.isTagged(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void assertNotCyclic(@Nonnull SlimefunTag tag) {
|
private void assertNotCyclic(@Nonnull SlimefunTag tag) {
|
||||||
Set<SlimefunTag> visiting = new HashSet<>();
|
Set<SlimefunTag> visiting = new HashSet<>();
|
||||||
Set<SlimefunTag> visited = new HashSet<>();
|
Set<SlimefunTag> visited = new HashSet<>();
|
@ -0,0 +1,116 @@
|
|||||||
|
package io.github.thebusybiscuit.slimefun4.testing.tests.tags;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Tag;
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||||
|
import be.seeseemelk.mockbukkit.ServerMock;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.utils.tags.TagParser;
|
||||||
|
|
||||||
|
class TestTagParser {
|
||||||
|
|
||||||
|
private static SlimefunPlugin plugin;
|
||||||
|
private static NamespacedKey key;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void load() {
|
||||||
|
ServerMock server = MockBukkit.mock();
|
||||||
|
plugin = MockBukkit.load(SlimefunPlugin.class);
|
||||||
|
TestUtilities.registerDefaultTags(server);
|
||||||
|
|
||||||
|
key = new NamespacedKey(plugin, "test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
public static void unload() {
|
||||||
|
MockBukkit.unmock();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test Keyed implementation")
|
||||||
|
void testkey() {
|
||||||
|
TagParser parser = new TagParser(key);
|
||||||
|
Assertions.assertEquals(key, parser.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test Nullability check")
|
||||||
|
void testNullability() {
|
||||||
|
TagParser parser = new TagParser(key);
|
||||||
|
Assertions.assertThrows(IllegalArgumentException.class, () -> parser.parse(null, this::identity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test JSON Parsing Error handling")
|
||||||
|
void testInvalidJson() {
|
||||||
|
assertMisconfiguration("");
|
||||||
|
assertMisconfiguration("hello world");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test no Arrays")
|
||||||
|
void testMissingArray() {
|
||||||
|
assertMisconfiguration("{}");
|
||||||
|
assertMisconfiguration("{\"values\":\"derp\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test invalid Type")
|
||||||
|
void testInvalidMaterial() {
|
||||||
|
assertMisconfiguration("{\"values\":[123456]}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test invalid Materials")
|
||||||
|
void testInvalidMaterials() {
|
||||||
|
assertMisconfiguration("{\"values\":[\"NO\"]}");
|
||||||
|
assertMisconfiguration("{\"values\":[\"lol:jk\"]}");
|
||||||
|
assertMisconfiguration("{\"values\":[\"minecraft:no\"]}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test invalid Minecraft Tags")
|
||||||
|
void testInvalidMinecraftTags() {
|
||||||
|
assertMisconfiguration("{\"values\":[\"#minecraft:never_gonna_give_you_up\"]}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test invalid Slimefun Tags")
|
||||||
|
void testInvalidSlimefunTags() {
|
||||||
|
assertMisconfiguration("{\"values\":[\"#slimefun:never_gonna_give_you_up\"]}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test invalid Object elements")
|
||||||
|
void testInvalidJSONObjects() {
|
||||||
|
assertMisconfiguration("{\"values\":[{}]}");
|
||||||
|
assertMisconfiguration("{\"values\":[{\"id\":123}]}");
|
||||||
|
assertMisconfiguration("{\"values\":[{\"id\":\"wooh\"}]}");
|
||||||
|
assertMisconfiguration("{\"values\":[{\"required\":false}]}");
|
||||||
|
assertMisconfiguration("{\"values\":[{\"id\":\"wooh\",\"required\":\"wooh\"}]}");
|
||||||
|
assertMisconfiguration("{\"values\":[{\"id\":\"wooh\",\"required\":true}]}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertMisconfiguration(@Nonnull String json) {
|
||||||
|
TagParser parser = new TagParser(key);
|
||||||
|
Assertions.assertThrows(TagMisconfigurationException.class, () -> parser.parse(json, this::identity));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void identity(Set<Material> a, Set<Tag<Material>> b) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user