diff options
author | Erik Broes <erikbroes@grum.nl> | 2012-01-29 11:22:11 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2012-01-29 11:22:11 +0100 |
commit | 4c2f57592d73b51d7e78b259dce843edd48b562b (patch) | |
tree | ceef5e3b1bae8daf088c61012c9cb008eff04d67 /src/test/java/org/bukkit/MaterialTest.java | |
parent | 1ea0037f490e014c705d93bec9fca0e1a524c3b1 (diff) | |
download | craftbukkit-4c2f57592d73b51d7e78b259dce843edd48b562b.tar craftbukkit-4c2f57592d73b51d7e78b259dce843edd48b562b.tar.gz craftbukkit-4c2f57592d73b51d7e78b259dce843edd48b562b.tar.lz craftbukkit-4c2f57592d73b51d7e78b259dce843edd48b562b.tar.xz craftbukkit-4c2f57592d73b51d7e78b259dce843edd48b562b.zip |
Add some testing
Diffstat (limited to 'src/test/java/org/bukkit/MaterialTest.java')
-rw-r--r-- | src/test/java/org/bukkit/MaterialTest.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/test/java/org/bukkit/MaterialTest.java b/src/test/java/org/bukkit/MaterialTest.java new file mode 100644 index 00000000..f4464fd8 --- /dev/null +++ b/src/test/java/org/bukkit/MaterialTest.java @@ -0,0 +1,68 @@ +package org.bukkit; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +import java.util.Map; + +import net.minecraft.server.Item; +import net.minecraft.server.ItemFood; + +import org.bukkit.support.AbstractTestingBase; +import org.junit.Test; + +import com.google.common.collect.Maps; + +public class MaterialTest extends AbstractTestingBase { + @Test + public void verifyMapping() { + Map<Integer, Material> materials = Maps.newHashMap(); + for (Material material : Material.values()) { + materials.put(material.getId(), material); + } + materials.remove(0); // Purge air. + + for (Item item : Item.byId) { + if (item == null) continue; + + int id = item.id; + String name = item.getName(); + int maxStackSize = item.getMaxStackSize(); + int maxDurability = item.getMaxDurability(); + + Material material = materials.remove(id); + + assertNotNull(String.format("org.bukkit.Material is missing id: %d named: %s", id, name), material); + + assertThat(String.format("org.bukkit.Material.%s maxStackSize:", material), material.getMaxStackSize(), is(maxStackSize)); + assertThat(String.format("org.bukkit.Material.%s maxDurability:", material), material.getMaxDurability(), is((short) maxDurability)); + } + + assertThat("org.bukkit.Material has too many entries", materials.values(), hasSize(0)); + } + + @Test + public void verifyIsEdible() { + Map<Integer, Material> materials = Maps.newHashMap(); + for (Material material : Material.values()) { + if (!material.isEdible()) continue; + materials.put(material.getId(), material); + } + + for (Item item : Item.byId) { + if (item == null) continue; + if (!(item instanceof ItemFood)) continue; + + int id = item.id; + String name = item.getName(); + + Material material = materials.remove(id); + + assertNotNull(String.format("org.bukkit.Material does not list id: %d named: %s edible", id, name), material); + } + + assertThat("org.bukkit.Material has entries marked edible that are not ItemFood", materials.values(), hasSize(0)); + } +} |