Add isRecord and new material method tests.

Cleaned up all of the CraftBukkit tests, including moving some tests
from MaterialTest to PerMaterialTest.
This commit is contained in:
Wesley Wolfe 2012-12-14 02:02:02 -06:00
parent 53b064ec79
commit 0f4c206f9b
8 changed files with 122 additions and 90 deletions

View file

@ -1,9 +1,9 @@
package org.bukkit;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.Collections;
import java.util.List;
import net.minecraft.server.AchievementList;
@ -17,7 +17,7 @@ import com.google.common.collect.Lists;
public class AchievementTest {
@Test
@SuppressWarnings("unchecked")
public void verifyMapping() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
public void verifyMapping() throws Throwable {
List<Achievement> achievements = Lists.newArrayList(Achievement.values());
for (net.minecraft.server.Achievement statistic : (List<net.minecraft.server.Achievement>) AchievementList.e) {
@ -29,9 +29,9 @@ public class AchievementTest {
Achievement subject = Achievement.getById(id);
assertNotNull(message, subject);
achievements.remove(subject);
assertTrue(name, achievements.remove(subject));
}
assertThat("org.bukkit.Achievement has too many achievements", achievements, hasSize(0));
assertThat("org.bukkit.Achievement has too many achievements", achievements, is(Collections.EMPTY_LIST));
}
}

View file

@ -1,10 +1,9 @@
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 static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
@ -41,7 +40,7 @@ public class ArtTest {
arts.remove(subject);
}
assertThat("org.bukkit.Art has too many arts", arts, hasSize(0));
assertThat("org.bukkit.Art has too many arts", arts, is(Collections.EMPTY_LIST));
}
@Test
@ -50,7 +49,7 @@ public class ArtTest {
for (Art art : Art.values()) {
EnumArt enumArt = CraftArt.BukkitToNotch(art);
assertNotNull(art.name(), enumArt);
assertThat(art.name(), cache.put(enumArt, art), is((Art) null));
assertThat(art.name(), cache.put(enumArt, art), is(nullValue()));
}
}
@ -60,7 +59,7 @@ public class ArtTest {
for (EnumArt enumArt : EnumArt.values()) {
Art art = CraftArt.NotchToBukkit(enumArt);
assertNotNull(enumArt.name(), art);
assertThat(enumArt.name(), cache.put(art, enumArt), is((EnumArt) null));
assertThat(enumArt.name(), cache.put(art, enumArt), is(nullValue()));
}
}
}

View file

@ -1,14 +1,12 @@
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 static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.Collections;
import java.util.Map;
import net.minecraft.server.Item;
import net.minecraft.server.ItemFood;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
@ -16,6 +14,7 @@ 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();
@ -29,40 +28,12 @@ public class MaterialTest extends AbstractTestingBase {
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("Missing " + name + "(" + id + ")", material, is(not(nullValue())));
}
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));
assertThat(materials, is(Collections.EMPTY_MAP));
}
}

View file

@ -3,27 +3,37 @@ package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.AchievementList;
import net.minecraft.server.Block;
import net.minecraft.server.BlockFire;
import net.minecraft.server.Item;
import net.minecraft.server.ItemFood;
import net.minecraft.server.ItemRecord;
import org.bukkit.support.AbstractTestingBase;
import org.bukkit.support.Util;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.collect.Lists;
@RunWith(Parameterized.class)
public class PerMaterialTest {
static {
AchievementList.a();
public class PerMaterialTest extends AbstractTestingBase {
private static int[] fireValues;
@BeforeClass
public static void getFireValues() {
fireValues = Util.getInternalState(BlockFire.class, Block.FIRE, "a");
}
@Parameters(name= "{index}: {0}")
public static List<Object[]> data() {
List<Object[]> list = new ArrayList<Object[]>();
List<Object[]> list = Lists.newArrayList();
for (Material material : Material.values()) {
list.add(new Object[] {material});
}
@ -42,4 +52,70 @@ public class PerMaterialTest {
assertFalse(material.isSolid());
}
}
@Test
public void isEdible() {
assertThat(material.isEdible(), is(Item.byId[material.getId()] instanceof ItemFood));
}
@Test
public void isRecord() {
assertThat(material.isRecord(), is(Item.byId[material.getId()] instanceof ItemRecord));
}
@Test
public void maxDurability() {
if (material == Material.AIR) {
assertThat((int) material.getMaxDurability(), is(0));
} else {
assertThat((int) material.getMaxDurability(), is(Item.byId[material.getId()].getMaxDurability()));
}
}
@Test
public void maxStackSize() {
if (material == Material.AIR) {
assertThat(material.getMaxStackSize(), is(64 /* Why can't I hold all of these AIR? */));
} else {
assertThat(material.getMaxStackSize(), is(Item.byId[material.getId()].getMaxStackSize()));
}
}
@Test
public void isTransparent() {
if (material == Material.AIR) {
assertTrue(material.isTransparent());
} else if (material.isBlock()) {
assertThat(material.isTransparent(), is(not(Block.byId[material.getId()].material.blocksLight())));
} else {
assertFalse(material.isTransparent());
}
}
@Test
public void isFlammable() {
if (material != Material.AIR && material.isBlock()) {
assertThat(material.isFlammable(), is(Block.byId[material.getId()].material.isBurnable()));
} else {
assertFalse(material.isFlammable());
}
}
@Test
public void isBurnable() {
if (material.isBlock()) {
assertThat(material.isBurnable(), is(fireValues[material.getId()] > 0));
} else {
assertFalse(material.isBurnable());
}
}
@Test
public void isOccluding() {
if (material.isBlock()) {
assertThat(material.isOccluding(), is(Block.i(material.getId())));
} else {
assertFalse(material.isOccluding());
}
}
}

View file

@ -1,6 +1,7 @@
package org.bukkit;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import org.bukkit.craftbukkit.CraftSound;
import org.junit.Test;
@ -11,7 +12,7 @@ public class SoundTest {
@Test
public void testGetSound() {
for (Sound sound : Sound.values()) {
assertNotNull(sound.name(), CraftSound.getSound(sound));
assertThat(sound.name(), CraftSound.getSound(sound), is(not(nullValue())));
}
}
}

View file

@ -1,9 +1,7 @@
package org.bukkit;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import net.minecraft.server.WorldType;
import org.junit.Test;
@ -11,21 +9,10 @@ import org.junit.Test;
public class WorldTypeTest {
@Test
public void testTypes() {
List<WorldType> missingTypes = new ArrayList<WorldType>();
for (WorldType type : WorldType.types) {
if (type == null) continue;
if (org.bukkit.WorldType.getByName(type.name()) == null) {
missingTypes.add(type);
}
}
if (!missingTypes.isEmpty()) {
for (WorldType type : missingTypes) {
System.out.println(type.name() + " is missing!");
}
fail("Missing (" + missingTypes.size() + ") WorldTypes!");
assertThat(type.name() + " has no Bukkit world", org.bukkit.WorldType.getByName(type.name()), is(not(nullValue())));
}
}
}

View file

@ -1,16 +1,15 @@
package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import net.minecraft.server.Enchantment;
import net.minecraft.server.StatisticList;
import org.bukkit.inventory.ItemStack;
import org.junit.Before;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
public class CraftItemStackTest {
@Before
public void setUp() throws Exception {
StatisticList.a();
}
public class CraftItemStackTest extends AbstractTestingBase {
@Test
public void testCloneEnchantedItem() throws Exception {
@ -18,12 +17,13 @@ public class CraftItemStackTest {
nmsItemStack.addEnchantment(Enchantment.DAMAGE_ALL, 1);
ItemStack itemStack = new CraftItemStack(nmsItemStack);
ItemStack clone = itemStack.clone();
assert (clone.getType().equals(itemStack.getType()));
assert (clone.getAmount() == itemStack.getAmount());
assert (clone.getDurability() == itemStack.getDurability());
assert (clone.getEnchantments().equals(itemStack.getEnchantments()));
assert (clone.getTypeId() == itemStack.getTypeId());
assert (clone.getData().equals(itemStack.getData()));
assertThat(clone.getType(), is(itemStack.getType()));
assertThat(clone.getAmount(), is(itemStack.getAmount()));
assertThat(clone.getDurability(), is(itemStack.getDurability()));
assertThat(clone.getEnchantments(), is(itemStack.getEnchantments()));
assertThat(clone.getTypeId(), is(itemStack.getTypeId()));
assertThat(clone.getData(), is(itemStack.getData()));
assertThat(clone, is(itemStack));
}
@Test
@ -31,6 +31,6 @@ public class CraftItemStackTest {
net.minecraft.server.ItemStack nmsItemStack = null;
ItemStack itemStack = new CraftItemStack(nmsItemStack);
ItemStack clone = itemStack.clone();
assert (clone.equals(itemStack));
assertThat(clone, is(itemStack));
}
}

View file

@ -3,11 +3,11 @@ package org.bukkit.potion;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.lang.reflect.Field;
import java.util.EnumMap;
import java.util.Map;
import org.bukkit.craftbukkit.potion.CraftPotionBrewer;
import org.bukkit.support.Util;
import org.junit.BeforeClass;
import org.junit.Test;
@ -36,9 +36,7 @@ public class PotionTest {
@Test
public void testEffectCompleteness() throws SecurityException, IllegalAccessException, NoSuchFieldException {
Field durationsField = net.minecraft.server.PotionBrewer.class.getDeclaredField("effectDurations");
durationsField.setAccessible(true);
Map<Integer, ?> effectDurations = (Map<Integer, ?>) durationsField.get(null);
Map<Integer, ?> effectDurations = Util.getInternalState(net.minecraft.server.PotionBrewer.class, null, "effectDurations");
Map<PotionType, String> effects = new EnumMap(PotionType.class);
for (int id : effectDurations.keySet()) {