diff options
author | Wesley Wolfe <weswolf@aol.com> | 2013-07-23 23:25:04 -0500 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2013-07-27 18:00:01 -0500 |
commit | 1e7f2ebebde28acf23a122c006fd5ed04c1baaf4 (patch) | |
tree | 6cf681eae8d5b3b06844469634668f2e3c92aa55 /src/test/java/org/bukkit | |
parent | b6fec0467f70f6c64a796f5fa9e382946bfe5d4b (diff) | |
download | craftbukkit-1e7f2ebebde28acf23a122c006fd5ed04c1baaf4.tar craftbukkit-1e7f2ebebde28acf23a122c006fd5ed04c1baaf4.tar.gz craftbukkit-1e7f2ebebde28acf23a122c006fd5ed04c1baaf4.tar.lz craftbukkit-1e7f2ebebde28acf23a122c006fd5ed04c1baaf4.tar.xz craftbukkit-1e7f2ebebde28acf23a122c006fd5ed04c1baaf4.zip |
Store item attributes. Addresses BUKKIT-4523
Diffstat (limited to 'src/test/java/org/bukkit')
-rw-r--r-- | src/test/java/org/bukkit/craftbukkit/inventory/ItemFactoryTest.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemFactoryTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemFactoryTest.java new file mode 100644 index 00000000..6e3690e2 --- /dev/null +++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemFactoryTest.java @@ -0,0 +1,45 @@ +package org.bukkit.craftbukkit.inventory; + +import static org.junit.Assert.*; +import static org.hamcrest.Matchers.*; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import net.minecraft.server.CommandAbstract; +import net.minecraft.server.IAttribute; +import org.bukkit.support.AbstractTestingBase; +import org.junit.Test; + +public class ItemFactoryTest extends AbstractTestingBase { + + @Test + public void testKnownAttributes() throws Throwable { + final ZipFile nmsZipFile = new ZipFile(CommandAbstract.class /* Magic class that isn't imported! */.getProtectionDomain().getCodeSource().getLocation().getFile()); + final Collection<String> names = new HashSet<String>(); + for (final ZipEntry clazzEntry : Collections.list(nmsZipFile.entries())) { + final String entryName = clazzEntry.getName(); + if (!(entryName.endsWith(".class") && entryName.startsWith("net/minecraft/server/"))) { + continue; + } + + final Class<?> clazz = Class.forName(entryName.substring(0, entryName.length() - ".class".length()).replace('/', '.')); + assertThat(entryName, clazz, is(not(nullValue()))); + for (final Field field : clazz.getDeclaredFields()) { + if (IAttribute.class.isAssignableFrom(field.getType()) && Modifier.isStatic(field.getModifiers())) { + field.setAccessible(true); + final String attributeName = ((IAttribute) field.get(null)).a(); + assertThat("Logical error: duplicate name `" + attributeName + "' in " + clazz.getName(), names.add(attributeName), is(true)); + assertThat(clazz.getName(), CraftItemFactory.KNOWN_NBT_ATTRIBUTE_NAMES, hasItem(attributeName)); + } + } + } + + assertThat("Extra values detected", CraftItemFactory.KNOWN_NBT_ATTRIBUTE_NAMES, is(names)); + } +} |