From 116cb9a1bce6b0aa51132be2950b1e6c6ecf73a0 Mon Sep 17 00:00:00 2001 From: Nathan Wolf Date: Wed, 26 Sep 2018 17:21:53 -0700 Subject: [PATCH] SPIGOT-4399: Add attribute modifier equality test --- .../craftbukkit/inventory/ItemMetaTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java index 00f89f2296..d4f8e8c30c 100644 --- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java +++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java @@ -6,6 +6,8 @@ import static org.hamcrest.Matchers.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.UUID; + import net.minecraft.server.Block; import net.minecraft.server.IRegistry; import net.minecraft.server.ITileEntity; @@ -21,6 +23,8 @@ import org.bukkit.FireworkEffect; import org.bukkit.Material; import org.bukkit.FireworkEffect.Type; import org.bukkit.NamespacedKey; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.PatternType; import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider; @@ -320,6 +324,26 @@ public class ItemMetaTest extends AbstractTestingBase { } } + @Test + public void testAttributeModifiers() { + UUID sameUUID = UUID.randomUUID(); + ItemMeta itemMeta = Bukkit.getItemFactory().getItemMeta(Material.DIAMOND_PICKAXE); + itemMeta.addAttributeModifier(Attribute.GENERIC_ATTACK_SPEED, new AttributeModifier(sameUUID, "Test Modifier", 10, AttributeModifier.Operation.ADD_NUMBER)); + + ItemMeta equalMeta = Bukkit.getItemFactory().getItemMeta(Material.DIAMOND_PICKAXE); + equalMeta.addAttributeModifier(Attribute.GENERIC_ATTACK_SPEED, new AttributeModifier(sameUUID, "Test Modifier", 10, AttributeModifier.Operation.ADD_NUMBER)); + + assertThat(itemMeta.equals(equalMeta), is(true)); + + ItemMeta itemMeta2 = Bukkit.getItemFactory().getItemMeta(Material.DIAMOND_PICKAXE); + itemMeta2.addAttributeModifier(Attribute.GENERIC_ATTACK_SPEED, new AttributeModifier(sameUUID, "Test Modifier", 10, AttributeModifier.Operation.ADD_NUMBER)); + + ItemMeta notEqualMeta2 = Bukkit.getItemFactory().getItemMeta(Material.DIAMOND_PICKAXE); + notEqualMeta2.addAttributeModifier(Attribute.GENERIC_ATTACK_SPEED, new AttributeModifier(sameUUID, "Test Modifier", 11, AttributeModifier.Operation.ADD_NUMBER)); + + assertThat(itemMeta2.equals(notEqualMeta2), is(false)); + } + private void downCastTest(final StackWrapper provider) { final String name = provider.toString(); final ItemStack blank = new ItemStack(Material.STONE);