1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.List;
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.craftbukkit.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
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 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 = Lists.newArrayList();
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());
}
}
@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() {
final ItemStack bukkit = new ItemStack(material);
final CraftItemStack craft = CraftItemStack.asCraftCopy(bukkit);
if (material == Material.AIR) {
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));
} else {
assertThat(material.getMaxStackSize(), is(Item.byId[material.getId()].getMaxStackSize()));
assertThat(bukkit.getMaxStackSize(), is(material.getMaxStackSize()));
assertThat(craft.getMaxStackSize(), is(material.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());
}
}
}
|