2012-12-09 22:13:38 +01:00
|
|
|
package org.bukkit;
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import static org.hamcrest.Matchers.*;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.server.Block;
|
2012-12-14 09:02:02 +01:00
|
|
|
import net.minecraft.server.BlockFire;
|
|
|
|
import net.minecraft.server.Item;
|
|
|
|
import net.minecraft.server.ItemFood;
|
|
|
|
import net.minecraft.server.ItemRecord;
|
2012-12-09 22:13:38 +01:00
|
|
|
|
2012-12-17 08:31:41 +01:00
|
|
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-12-14 09:02:02 +01:00
|
|
|
import org.bukkit.support.AbstractTestingBase;
|
|
|
|
import org.bukkit.support.Util;
|
|
|
|
import org.junit.BeforeClass;
|
2012-12-09 22:13:38 +01:00
|
|
|
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;
|
|
|
|
|
2012-12-14 09:02:02 +01:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
2012-12-09 22:13:38 +01:00
|
|
|
@RunWith(Parameterized.class)
|
2012-12-14 09:02:02 +01:00
|
|
|
public class PerMaterialTest extends AbstractTestingBase {
|
|
|
|
private static int[] fireValues;
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void getFireValues() {
|
|
|
|
fireValues = Util.getInternalState(BlockFire.class, Block.FIRE, "a");
|
2012-12-09 22:13:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Parameters(name= "{index}: {0}")
|
|
|
|
public static List<Object[]> data() {
|
2012-12-14 09:02:02 +01:00
|
|
|
List<Object[]> list = Lists.newArrayList();
|
2012-12-09 22:13:38 +01:00
|
|
|
for (Material material : Material.values()) {
|
|
|
|
list.add(new Object[] {material});
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Parameter public Material material;
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void isSolid() {
|
|
|
|
if (material == Material.AIR) {
|
|
|
|
assertFalse(material.isSolid());
|
|
|
|
} else if (material.isBlock()) {
|
|
|
|
assertThat(material.isSolid(), is(Block.byId[material.getId()].material.isSolid()));
|
|
|
|
} else {
|
|
|
|
assertFalse(material.isSolid());
|
|
|
|
}
|
|
|
|
}
|
2012-12-14 09:02:02 +01:00
|
|
|
|
|
|
|
@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() {
|
2012-12-17 08:31:41 +01:00
|
|
|
final ItemStack bukkit = new ItemStack(material);
|
|
|
|
final CraftItemStack craft = CraftItemStack.asCraftCopy(bukkit);
|
2012-12-14 09:02:02 +01:00
|
|
|
if (material == Material.AIR) {
|
2012-12-17 08:31:41 +01:00
|
|
|
final int MAX_AIR_STACK = 0 /* Why can't I hold all of these AIR? */;
|
|
|
|
assertThat(material.getMaxStackSize(), is(MAX_AIR_STACK));
|
|
|
|
assertThat(bukkit.getMaxStackSize(), is(MAX_AIR_STACK));
|
|
|
|
assertThat(craft.getMaxStackSize(), is(MAX_AIR_STACK));
|
2012-12-14 09:02:02 +01:00
|
|
|
} else {
|
|
|
|
assertThat(material.getMaxStackSize(), is(Item.byId[material.getId()].getMaxStackSize()));
|
2012-12-17 08:31:41 +01:00
|
|
|
assertThat(bukkit.getMaxStackSize(), is(material.getMaxStackSize()));
|
|
|
|
assertThat(craft.getMaxStackSize(), is(material.getMaxStackSize()));
|
2012-12-14 09:02:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
assertThat(material.isOccluding(), is(Block.l(material.getId())));
|
2012-12-14 09:02:02 +01:00
|
|
|
} else {
|
|
|
|
assertFalse(material.isOccluding());
|
|
|
|
}
|
|
|
|
}
|
2012-12-09 22:13:38 +01:00
|
|
|
}
|