A lot of tests, and some improvements
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
Adds a lot more tests for some utility classes Adds a new option to disable the hard-coded limitation "EnchantmentTarget.BREAKABLE" which can be useful for servers with custom items or similar. Makes enchantment name matching case-insensitive. Prevents an exception is enchantment name contains invalid characters. Makes invalid objects supplied to asStringList return null instead of throwing an exception. Uses isBlank instead of trim.isEmpty in the isEmpty method Re-uses the random generator if calculating salvage several times
This commit is contained in:
@ -0,0 +1,62 @@
|
||||
package net.knarcraft.blacksmith.util;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import net.knarcraft.blacksmith.CustomServerMock;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for the ItemHelper class
|
||||
*/
|
||||
public class ItemHelperTest {
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
MockBukkit.mock(new CustomServerMock());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void tearDown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isRepairableTest() {
|
||||
for (Material material : Material.values()) {
|
||||
String name = material.name();
|
||||
if (name.endsWith("_SWORD") || name.endsWith("_PICKAXE") || name.endsWith("_AXE") ||
|
||||
name.endsWith("_HOE") || name.endsWith("_SHOVEL") || name.endsWith("_CHESTPLATE") ||
|
||||
name.endsWith("_HELMET") || name.equals("ELYTRA") || name.endsWith("BOW") ||
|
||||
name.endsWith("_LEGGINGS") || name.endsWith("_BOOTS") || name.equals("TRIDENT") ||
|
||||
name.equals("FISHING_ROD") || name.equals("FLINT_AND_STEEL") || name.equals("SHEARS")) {
|
||||
assertTrue(ItemHelper.isRepairable(new ItemStack(material, 1), false));
|
||||
}
|
||||
}
|
||||
assertFalse(ItemHelper.isRepairable(new ItemStack(Material.POTATO, 1), false));
|
||||
assertFalse(ItemHelper.isRepairable(new ItemStack(Material.DIRT, 1), false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isRepairableLimitDisabledTest() {
|
||||
/*The assertFalse pert of this test is kind of pointless, as every material in the game seems to implement
|
||||
Damageable */
|
||||
for (Material material : Material.values()) {
|
||||
ItemStack itemStack = new ItemStack(material, 1);
|
||||
if (new ItemStack(material, 1).getItemMeta() instanceof Damageable) {
|
||||
assertTrue(ItemHelper.isRepairable(itemStack, true));
|
||||
} else {
|
||||
assertFalse(ItemHelper.isRepairable(itemStack, true));
|
||||
}
|
||||
}
|
||||
assertTrue(ItemHelper.isRepairable(new ItemStack(Material.POTATO, 1), true));
|
||||
assertTrue(ItemHelper.isRepairable(new ItemStack(Material.DIRT, 1), true));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user