1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

[CI skip] Added more Unit tests

This commit is contained in:
TheBusyBiscuit 2020-08-23 17:56:38 +02:00
parent ec95797cbf
commit f51a19777f
13 changed files with 206 additions and 76 deletions

32
pom.xml
View File

@ -13,7 +13,7 @@
<inceptionYear>2013</inceptionYear>
<packaging>jar</packaging>
<description>Slimefun is a Spigot plugin that simulates a modpack-like atmosphere by adding over 500 new items and recipes to your Minecraft Server.</description>
<description>Slimefun is a Spigot/Paper plugin that simulates a modpack-like atmosphere by adding over 500 new items and recipes to your Minecraft Server.</description>
<url>https://github.com/TheBusyBiscuit/Slimefun4</url>
<properties>
@ -47,16 +47,6 @@
</licenses>
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
@ -221,7 +211,7 @@
<detectOfflineLinks>false</detectOfflineLinks>
<additionalJOption>-html5</additionalJOption>
<!-- We can reference Bukkit's API in our Javadocs -->
<!-- We can reference the Spigot API in our Javadocs -->
<links>
<link>${spigot.javadocs}</link>
</links>
@ -313,8 +303,8 @@
</dependency>
<dependency>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.15</artifactId>
<version>0.3.1-SNAPSHOT</version>
<artifactId>MockBukkit-v1.16</artifactId>
<version>0.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
@ -337,10 +327,17 @@
<version>1.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.9.00</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.google.code.gson</groupId>
@ -348,12 +345,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.5</version>
<scope>compile</scope>
</dependency>
<!-- Third party plugin integrations -->
<dependency>
@ -370,7 +361,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>

View File

@ -0,0 +1,28 @@
package io.github.thebusybiscuit.slimefun4.api.items;
import org.apache.commons.lang.Validate;
public class RangedItemSetting extends ItemSetting<Integer> {
private final int min;
private final int max;
public RangedItemSetting(String key, int min, int defaultValue, int max) {
super(key, defaultValue);
this.min = min;
this.max = max;
Validate.isTrue(defaultValue >= min && defaultValue <= max, "The default value must be equal to or inbetween the minimum and maximum.");
}
@Override
public boolean validateInput(Integer input) {
return super.validateInput(input) && input.intValue() >= min && input.intValue() <= max;
}
public int getIntValue() {
return getValue().intValue();
}
}

View File

@ -1,6 +1,5 @@
package io.github.thebusybiscuit.slimefun4.core.services;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
@ -11,6 +10,10 @@ import java.nio.file.StandardCopyOption;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import javax.annotation.Nullable;
import org.bukkit.plugin.Plugin;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import kong.unirest.GetRequest;
@ -19,7 +22,6 @@ import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import kong.unirest.UnirestException;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import org.bukkit.plugin.Plugin;
/**
* This Class represents a Metrics Service that sends data to https://bstats.org/
@ -31,7 +33,6 @@ import org.bukkit.plugin.Plugin;
* @author WalshyDev
*/
public class MetricsService {
private static final String API_URL = "https://api.github.com/";
private static final String REPO_NAME = "MetricsModule";

View File

@ -165,6 +165,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
if (minecraftVersion == MinecraftVersion.UNIT_TEST) {
local = new LocalizationService(this, "", null);
gpsNetwork = new GPSNetwork();
networkManager = new NetworkManager(200);
command.register();
registry.load(config);
}

View File

@ -1,7 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import org.bukkit.ChatColor;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -18,7 +17,7 @@ public class FireworksListener implements Listener {
@EventHandler
public void onResearchFireworkDamage(EntityDamageByEntityEvent e) {
if (e.getDamager().getType() == EntityType.FIREWORK) {
if (e.getDamager() instanceof Firework) {
Firework firework = (Firework) e.getDamager();
FireworkMeta meta = firework.getFireworkMeta();

View File

@ -13,6 +13,12 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.inventory.meta.FireworkMeta;
/**
* This is a simple utility classs for spawning random and colorful {@link Firework} rockets.
*
* @author TheBusyBiscuit
*
*/
public final class FireworkUtils {
private static final Color[] COLORS = { Color.AQUA, Color.BLACK, Color.BLUE, Color.FUCHSIA, Color.GRAY, Color.GREEN, Color.LIME, Color.MAROON, Color.NAVY, Color.OLIVE, Color.ORANGE, Color.PURPLE, Color.RED, Color.SILVER, Color.TEAL, Color.WHITE, Color.YELLOW };
@ -20,6 +26,10 @@ public final class FireworkUtils {
private FireworkUtils() {}
public static void launchFirework(Location l, Color color) {
createFirework(l, color);
}
public static Firework createFirework(Location l, Color color) {
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
FireworkMeta meta = fw.getFireworkMeta();
@ -28,28 +38,17 @@ public final class FireworkUtils {
meta.addEffect(effect);
meta.setPower(ThreadLocalRandom.current().nextInt(2) + 1);
fw.setFireworkMeta(meta);
}
public static Firework createFirework(Location l, Color color) {
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
FireworkMeta meta = fw.getFireworkMeta();
meta.setDisplayName(ChatColor.GREEN + "Slimefun Research");
FireworkEffect effect = FireworkEffect.builder().flicker(ThreadLocalRandom.current().nextBoolean()).withColor(color).with(ThreadLocalRandom.current().nextInt(3) + 1 == 1 ? Type.BALL : Type.BALL_LARGE).trail(ThreadLocalRandom.current().nextBoolean()).build();
meta.addEffect(effect);
meta.setPower(ThreadLocalRandom.current().nextInt(2) + 1);
fw.setFireworkMeta(meta);
return fw;
}
public static void launchRandom(Entity n, int amount) {
Random random = ThreadLocalRandom.current();
for (int i = 0; i < amount; i++) {
Location l = n.getLocation().clone();
l.setX(l.getX() + ThreadLocalRandom.current().nextInt(amount));
l.setX(l.getX() - ThreadLocalRandom.current().nextInt(amount));
l.setZ(l.getZ() + ThreadLocalRandom.current().nextInt(amount));
l.setZ(l.getZ() - ThreadLocalRandom.current().nextInt(amount));
l.setX(l.getX() + random.nextInt(amount * 2) - amount);
l.setZ(l.getZ() + random.nextInt(amount * 2) - amount);
launchFirework(l, getRandomColor());
}

View File

@ -3,13 +3,14 @@ package io.github.thebusybiscuit.slimefun4.testing.tests;
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 io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
public class TestPluginClass {
class TestPluginClass {
@BeforeAll
public static void load() {
@ -23,7 +24,8 @@ public class TestPluginClass {
}
@Test
public void verifyTestEnvironment() {
@DisplayName("Verify that we are in a UNIT_TEST environment")
void verifyTestEnvironment() {
MinecraftVersion version = SlimefunPlugin.getMinecraftVersion();
Assertions.assertEquals(MinecraftVersion.UNIT_TEST, version);
@ -31,22 +33,28 @@ public class TestPluginClass {
}
@Test
public void testConfigs() {
@DisplayName("Verify that config files were loaded")
void testConfigs() {
Assertions.assertNotNull(SlimefunPlugin.getCfg());
Assertions.assertNotNull(SlimefunPlugin.getResearchCfg());
Assertions.assertNotNull(SlimefunPlugin.getItemCfg());
}
@Test
public void testGetters() {
@DisplayName("Test some static Getters")
void testGetters() {
Assertions.assertNotNull(SlimefunPlugin.getTickerTask());
Assertions.assertNotNull(SlimefunPlugin.getVersion());
Assertions.assertNotNull(SlimefunPlugin.getRegistry());
Assertions.assertNotNull(SlimefunPlugin.getCommand());
Assertions.assertNotNull(SlimefunPlugin.getGPSNetwork());
Assertions.assertNotNull(SlimefunPlugin.getNetworkManager());
Assertions.assertNotNull(SlimefunPlugin.getProfiler());
}
@Test
public void testServicesNotNull() {
@DisplayName("Test some Services being not-null")
void testServicesNotNull() {
Assertions.assertNotNull(SlimefunPlugin.getLocalization());
Assertions.assertNotNull(SlimefunPlugin.getMinecraftRecipeService());
Assertions.assertNotNull(SlimefunPlugin.getItemDataService());
@ -57,10 +65,12 @@ public class TestPluginClass {
Assertions.assertNotNull(SlimefunPlugin.getWorldSettingsService());
Assertions.assertNotNull(SlimefunPlugin.getGitHubService());
Assertions.assertNotNull(SlimefunPlugin.getUpdater());
Assertions.assertNotNull(SlimefunPlugin.getMetricsService());
}
@Test
public void testListenersNotNull() {
@DisplayName("Test some Listeners being not-null")
void testListenersNotNull() {
Assertions.assertNotNull(SlimefunPlugin.getAncientAltarListener());
Assertions.assertNotNull(SlimefunPlugin.getGrapplingHookListener());
Assertions.assertNotNull(SlimefunPlugin.getBackpackListener());

View File

@ -1,24 +1,21 @@
package io.github.thebusybiscuit.slimefun4.testing.tests.listeners;
import org.bukkit.ChatColor;
import org.bukkit.entity.EntityType;
import org.bukkit.Color;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.meta.FireworkMeta;
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 org.mockito.Mockito;
import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import be.seeseemelk.mockbukkit.inventory.meta.FireworkMetaMock;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.FireworksListener;
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
class TestFireworksListener {
@ -40,12 +37,7 @@ class TestFireworksListener {
@DisplayName("Test if Fireworks from Research cause no damage")
void testFireworkDamage() {
Player player = server.addPlayer();
Firework firework = Mockito.mock(Firework.class);
FireworkMeta meta = new FireworkMetaMock();
meta.setDisplayName(ChatColor.GREEN + "Slimefun Research");
Mockito.when(firework.getType()).thenReturn(EntityType.FIREWORK);
Mockito.when(firework.getFireworkMeta()).thenReturn(meta);
Firework firework = FireworkUtils.createFirework(player.getLocation(), Color.BLUE);
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(firework, player, DamageCause.ENTITY_EXPLOSION, 6.0);
server.getPluginManager().callEvent(event);

View File

@ -5,10 +5,15 @@ import java.util.Optional;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
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 org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
@ -18,7 +23,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
public class TestPermissionsService {
class TestPermissionsService {
private static ServerMock server;
private static SlimefunPlugin plugin;
@ -34,18 +39,24 @@ public class TestPermissionsService {
MockBukkit.unmock();
}
@Test
public void testRegistration() {
@ParameterizedTest
@DisplayName("Test if no permission is set by default")
@ValueSource(booleans = { false, true })
void testDefaultPermission(boolean registered) {
PermissionsService service = new PermissionsService(plugin);
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
service.register(Arrays.asList(item), false);
if (registered) {
service.register(Arrays.asList(item), false);
}
Optional<String> permission = service.getPermission(item);
Assertions.assertFalse(permission.isPresent());
}
@Test
public void testSetPermission() {
@DisplayName("Test if a permission node can be set")
void testSetPermission() {
PermissionsService service = new PermissionsService(plugin);
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
@ -65,7 +76,8 @@ public class TestPermissionsService {
}
@Test
public void testHasPermissionTrue() {
@DisplayName("Test if the Player will pass the permissions check if no permission was set")
void testHasPermissionTrue() {
PermissionsService service = new PermissionsService(plugin);
Player player = server.addPlayer();
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
@ -78,7 +90,8 @@ public class TestPermissionsService {
}
@Test
public void testHasPermissionFalse() {
@DisplayName("Test Players without permissions being denied access")
void testHasPermissionFalse() {
PermissionsService service = new PermissionsService(plugin);
Player player = server.addPlayer();
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
@ -86,4 +99,32 @@ public class TestPermissionsService {
service.setPermission(item, "slimefun.tests");
Assertions.assertFalse(service.hasPermission(player, item));
}
@Test
@DisplayName("Test Server Operators passing permission checks")
void testHasPermissionOp() {
PermissionsService service = new PermissionsService(plugin);
Player player = server.addPlayer();
player.setOp(true);
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
Permission permission = new Permission("slimefun.unit.tests.op", PermissionDefault.OP);
service.setPermission(item, permission.getName());
Assertions.assertTrue(service.hasPermission(player, item));
}
@Test
@DisplayName("Test Player with permission passing the permission check")
void testHasPermissionSet() {
PermissionsService service = new PermissionsService(plugin);
Player player = server.addPlayer();
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
String permission = "slimefun.unit.tests.permission";
player.addAttachment(plugin, permission, true);
service.setPermission(item, permission);
Assertions.assertTrue(service.hasPermission(player, item));
}
}

View File

@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.utils;
import org.bukkit.ChatColor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
@ -10,6 +11,7 @@ import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
class TestChatUtils {
@Test
@DisplayName("Test ChatUtils.humanize(...)")
void testHumanize() {
String input = "TEST_STRING_COOL";
String expected = "Test String Cool";
@ -17,6 +19,7 @@ class TestChatUtils {
}
@Test
@DisplayName("Test ChatUtils.christmas(...)")
void testChristmas() {
String input = "Tis the season";
String expected = ChatColors.color("&aT&ci&as&c &at&ch&ae&c &as&ce&aa&cs&ao&cn");
@ -24,6 +27,7 @@ class TestChatUtils {
}
@Test
@DisplayName("Test ChatUtils.removeColorCodes(...)")
void testColorCodeRemoval() {
String expected = "Hello world";
Assertions.assertEquals(expected, ChatUtils.removeColorCodes("&4&lHello &6world"));

View File

@ -0,0 +1,54 @@
package io.github.thebusybiscuit.slimefun4.testing.tests.utils;
import java.util.List;
import java.util.stream.Stream;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.entity.Firework;
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.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.WorldMock;
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
class TestFireworkUtils {
@BeforeAll
public static void load() {
MockBukkit.mock();
}
@AfterAll
public static void unload() {
MockBukkit.unmock();
}
@ParameterizedTest
@MethodSource("getColors")
@DisplayName("Test colored Fireworks")
void testColoredFirework(Color color) {
Location l = new Location(new WorldMock(), 50, 50, 50);
Firework firework = FireworkUtils.createFirework(l, color);
Assertions.assertEquals(l, firework.getLocation());
Assertions.assertEquals(ChatColor.GREEN + "Slimefun Research", firework.getFireworkMeta().getDisplayName());
List<FireworkEffect> effects = firework.getFireworkMeta().getEffects();
Assertions.assertEquals(1, effects.size());
Assertions.assertEquals(color, effects.get(0).getColors().get(0));
}
private static Stream<Arguments> getColors() {
return Stream.of(Color.RED, Color.BLUE, Color.YELLOW, Color.fromRGB(100, 20, 100)).map(Arguments::of);
}
}

View File

@ -1,14 +1,16 @@
package io.github.thebusybiscuit.slimefun4.testing.tests.utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
public class TestMinecraftVersion {
class TestMinecraftVersion {
@Test
public void testMatches() {
@DisplayName("Test if Minecraft versions match themselves")
void testMatches() {
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_13.matches("v1_13_R1"));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_14.matches("v1_14_R2"));
@ -18,7 +20,8 @@ public class TestMinecraftVersion {
}
@Test
public void testAtLeast() {
@DisplayName("Test if Minecraft versions are ordered correctly (#atLeast)")
void testAtLeast() {
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_15.isAtLeast(MinecraftVersion.MINECRAFT_1_13));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_15.isAtLeast(MinecraftVersion.MINECRAFT_1_14));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_15.isAtLeast(MinecraftVersion.MINECRAFT_1_15));
@ -27,7 +30,8 @@ public class TestMinecraftVersion {
}
@Test
public void testAtLeastUnknown() {
@DisplayName("Test correct behaviour for MinecraftVersion.UNKNOWN.isAtleast(...)")
void testAtLeastUnknown() {
// Unknown should always fall back to false
Assertions.assertFalse(MinecraftVersion.UNKNOWN.isAtLeast(MinecraftVersion.MINECRAFT_1_13));
Assertions.assertFalse(MinecraftVersion.UNKNOWN.isAtLeast(MinecraftVersion.MINECRAFT_1_15));
@ -36,7 +40,8 @@ public class TestMinecraftVersion {
}
@Test
public void testIsBefore() {
@DisplayName("Test if Minecraft versions are ordered correctly (#isBefore)")
void testIsBefore() {
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_13.isBefore(MinecraftVersion.MINECRAFT_1_14));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_13.isBefore(MinecraftVersion.MINECRAFT_1_15));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_14.isBefore(MinecraftVersion.MINECRAFT_1_15));
@ -46,7 +51,8 @@ public class TestMinecraftVersion {
}
@Test
public void testIsBeforeUnknown() {
@DisplayName("Test correct behaviour for MinecraftVersion.UNKNOWN.isBefore(...)")
void testIsBeforeUnknown() {
// Unknown should always fall back to true
Assertions.assertTrue(MinecraftVersion.UNKNOWN.isBefore(MinecraftVersion.MINECRAFT_1_13));
Assertions.assertTrue(MinecraftVersion.UNKNOWN.isBefore(MinecraftVersion.MINECRAFT_1_15));

View File

@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
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;
@ -18,7 +19,7 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class TestSoulboundItem {
class TestSoulboundItem {
private static SlimefunPlugin plugin;
@ -34,7 +35,8 @@ public class TestSoulboundItem {
}
@Test
public void testNullAndAir() {
@DisplayName("Verify that null and air throw Illegal Argument Exceptions")
void testNullAndAir() {
Assertions.assertThrows(IllegalArgumentException.class, () -> SlimefunUtils.setSoulbound(null, true));
ItemStack item = new ItemStack(Material.AIR);
@ -45,7 +47,8 @@ public class TestSoulboundItem {
}
@Test
public void testSetSoulbound() {
@DisplayName("Test whether an Item can be marked as soulbound")
void testSetSoulbound() {
ItemStack item = new CustomItem(Material.DIAMOND, "&cI wanna be soulbound!");
Assertions.assertFalse(SlimefunUtils.isSoulbound(item));
@ -60,7 +63,8 @@ public class TestSoulboundItem {
}
@Test
public void testDoubleCalls() {
@DisplayName("Make sure that marking an item as soulbound twice has no effect")
void testDoubleCalls() {
ItemStack item = new CustomItem(Material.DIAMOND, "&cI wanna be soulbound!");
SlimefunUtils.setSoulbound(item, true);
@ -75,7 +79,8 @@ public class TestSoulboundItem {
}
@Test
public void testSoulboundSlimefunItem() {
@DisplayName("Test that soulbound Slimefun Items are soulbound")
void testSoulboundSlimefunItem() {
SlimefunItem item = new SoulboundMock(new Category(new NamespacedKey(plugin, "soulbound_category"), new CustomItem(Material.REDSTONE, "&4Walshrus forever")));
item.register(plugin);