summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/bukkit
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/bukkit')
-rw-r--r--src/test/java/org/bukkit/ArtTest.java30
-rw-r--r--src/test/java/org/bukkit/BlockDataTest.java58
-rw-r--r--src/test/java/org/bukkit/DyeColorsTest.java5
-rw-r--r--src/test/java/org/bukkit/EnchantmentTest.java24
-rw-r--r--src/test/java/org/bukkit/LegacyTest.java89
-rw-r--r--src/test/java/org/bukkit/MaterialTest.java8
-rw-r--r--src/test/java/org/bukkit/ParticleTest.java25
-rw-r--r--src/test/java/org/bukkit/PerMaterialTest.java22
-rw-r--r--src/test/java/org/bukkit/StatisticsAndAchievementsTest.java46
-rw-r--r--src/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java21
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java31
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/ItemFactoryTest.java4
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java62
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/ItemStackBookTest.java2
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkChargeTest.java2
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkTest.java2
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/ItemStackMapTest.java2
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/ItemStackSkullTest.java2
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/NMSCraftItemStackTest.java1
-rw-r--r--src/test/java/org/bukkit/entity/EntityTypesTest.java29
-rw-r--r--src/test/java/org/bukkit/entity/TropicalFishTest.java45
-rw-r--r--src/test/java/org/bukkit/map/MapTest.java2
-rw-r--r--src/test/java/org/bukkit/potion/PotionTest.java2
-rw-r--r--src/test/java/org/bukkit/support/AbstractTestingBase.java87
-rw-r--r--src/test/java/org/bukkit/support/DummyServer.java20
25 files changed, 465 insertions, 156 deletions
diff --git a/src/test/java/org/bukkit/ArtTest.java b/src/test/java/org/bukkit/ArtTest.java
index 7f402889..29d14d4b 100644
--- a/src/test/java/org/bukkit/ArtTest.java
+++ b/src/test/java/org/bukkit/ArtTest.java
@@ -5,10 +5,12 @@ import static org.hamcrest.Matchers.*;
import java.util.Collections;
import java.util.EnumMap;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import net.minecraft.server.EntityPainting.EnumArt;
+import net.minecraft.server.MinecraftKey;
+import net.minecraft.server.Paintings;
import org.bukkit.craftbukkit.CraftArt;
import org.junit.Test;
@@ -22,15 +24,15 @@ public class ArtTest {
public void verifyMapping() {
List<Art> arts = Lists.newArrayList(Art.values());
- for (EnumArt enumArt : EnumArt.values()) {
- int id = enumArt.ordinal();
- String name = enumArt.B;
- int width = enumArt.C / UNIT_MULTIPLIER;
- int height = enumArt.D / UNIT_MULTIPLIER;
+ for (MinecraftKey key : Paintings.a.keySet()) {
+ Paintings enumArt = Paintings.a.get(key);
+ String name = key.getKey();
+ int width = enumArt.b() / UNIT_MULTIPLIER;
+ int height = enumArt.c() / UNIT_MULTIPLIER;
- Art subject = Art.getById(id);
+ Art subject = CraftArt.NotchToBukkit(enumArt);
- String message = String.format("org.bukkit.Art is missing id: %d named: '%s'", id, name);
+ String message = String.format("org.bukkit.Art is missing '%s'", name);
assertNotNull(message, subject);
assertThat(Art.getByName(name), is(subject));
@@ -45,9 +47,9 @@ public class ArtTest {
@Test
public void testCraftArtToNotch() {
- Map<EnumArt, Art> cache = new EnumMap(EnumArt.class);
+ Map<Paintings, Art> cache = new HashMap<>();
for (Art art : Art.values()) {
- EnumArt enumArt = CraftArt.BukkitToNotch(art);
+ Paintings enumArt = CraftArt.BukkitToNotch(art);
assertNotNull(art.name(), enumArt);
assertThat(art.name(), cache.put(enumArt, art), is(nullValue()));
}
@@ -55,11 +57,11 @@ public class ArtTest {
@Test
public void testCraftArtToBukkit() {
- Map<Art, EnumArt> cache = new EnumMap(Art.class);
- for (EnumArt enumArt : EnumArt.values()) {
+ Map<Art, Paintings> cache = new EnumMap(Art.class);
+ for (Paintings enumArt : (Iterable<Paintings>) Paintings.a) { // Eclipse fail
Art art = CraftArt.NotchToBukkit(enumArt);
- assertNotNull(enumArt.name(), art);
- assertThat(enumArt.name(), cache.put(art, enumArt), is(nullValue()));
+ assertNotNull("Could not CraftArt.NotchToBukkit " + enumArt, art);
+ assertThat("Duplicate artwork " + enumArt, cache.put(art, enumArt), is(nullValue()));
}
}
}
diff --git a/src/test/java/org/bukkit/BlockDataTest.java b/src/test/java/org/bukkit/BlockDataTest.java
new file mode 100644
index 00000000..a5cea50b
--- /dev/null
+++ b/src/test/java/org/bukkit/BlockDataTest.java
@@ -0,0 +1,58 @@
+package org.bukkit;
+
+import net.minecraft.server.BlockCake;
+import net.minecraft.server.Blocks;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.block.data.type.Cake;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.support.AbstractTestingBase;
+import static org.hamcrest.Matchers.*;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BlockDataTest extends AbstractTestingBase {
+
+ @Test
+ public void testParsing() {
+ BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.getBlockData().set(BlockCake.BITES, 3));
+
+ BlockData materialString = CraftBlockData.newData(Material.CAKE, "[bites=3]");
+ Assert.assertThat(materialString, is(cakeTest));
+
+ BlockData combined = CraftBlockData.newData(null, "cake[bites=3]");
+ Assert.assertThat(combined, is(cakeTest));
+
+ BlockData combinedMinecraft = CraftBlockData.newData(null, "minecraft:cake[bites=3]");
+ Assert.assertThat(combinedMinecraft, is(cakeTest));
+
+ BlockData inverted = CraftBlockData.newData(null, cakeTest.getAsString());
+ Assert.assertThat(inverted, is(cakeTest));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBadMaterial() {
+ CraftBlockData.newData(null, "invalid");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testBadSyntax() {
+ CraftBlockData.newData(null, "minecraft:cake[bites=3");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testDoubleMaterial() {
+ CraftBlockData.newData(Material.CAKE, "minecraft:cake[bites=3]");
+ }
+
+ @Test
+ public void testClone() {
+ Cake cakeTest = (Cake) CraftBlockData.fromData(Blocks.CAKE.getBlockData().set(BlockCake.BITES, 3));
+ Cake clone = (Cake) cakeTest.clone();
+
+ Assert.assertFalse("Clone did not return new object", cakeTest == clone);
+ Assert.assertThat("Clone is not equal", clone, is(cakeTest));
+
+ clone.setBites(1);
+ Assert.assertThat("Clone is not actually clone", clone, is(not(cakeTest)));
+ }
+}
diff --git a/src/test/java/org/bukkit/DyeColorsTest.java b/src/test/java/org/bukkit/DyeColorsTest.java
index 020714da..45a5caed 100644
--- a/src/test/java/org/bukkit/DyeColorsTest.java
+++ b/src/test/java/org/bukkit/DyeColorsTest.java
@@ -7,7 +7,6 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.EnumColor;
-import net.minecraft.server.ItemDye;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
@@ -33,7 +32,7 @@ public class DyeColorsTest extends AbstractTestingBase {
@Test
public void checkColor() {
Color color = dye.getColor();
- float[] nmsColorArray = EnumColor.fromColorIndex(dye.getWoolData()).f();
+ float[] nmsColorArray = EnumColor.fromColorIndex(dye.getWoolData()).d();
Color nmsColor = Color.fromRGB((int) (nmsColorArray[0] * 255), (int) (nmsColorArray[1] * 255), (int) (nmsColorArray[2] * 255));
assertThat(color, is(nmsColor));
}
@@ -41,7 +40,7 @@ public class DyeColorsTest extends AbstractTestingBase {
@Test
public void checkFireworkColor() {
Color color = dye.getFireworkColor();
- int nmsColor = ItemDye.a[dye.getDyeData()];
+ int nmsColor = EnumColor.fromColorIndex(dye.getWoolData()).f();
assertThat(color, is(Color.fromRGB(nmsColor)));
}
}
diff --git a/src/test/java/org/bukkit/EnchantmentTest.java b/src/test/java/org/bukkit/EnchantmentTest.java
new file mode 100644
index 00000000..86bfbb45
--- /dev/null
+++ b/src/test/java/org/bukkit/EnchantmentTest.java
@@ -0,0 +1,24 @@
+package org.bukkit;
+
+import net.minecraft.server.MinecraftKey;
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.support.AbstractTestingBase;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class EnchantmentTest extends AbstractTestingBase {
+
+ @Test
+ public void verifyMapping() {
+ for (MinecraftKey key : net.minecraft.server.Enchantment.enchantments.keySet()) {
+ net.minecraft.server.Enchantment nms = net.minecraft.server.Enchantment.enchantments.get(key);
+
+ Enchantment bukkitById = Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(key));
+
+ Assert.assertFalse("Unknown enchant name for " + key, bukkitById.getName().startsWith("UNKNOWN"));
+
+ Assert.assertNotNull("Unknown target for " + key, bukkitById.getItemTarget());
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/LegacyTest.java b/src/test/java/org/bukkit/LegacyTest.java
new file mode 100644
index 00000000..543e7581
--- /dev/null
+++ b/src/test/java/org/bukkit/LegacyTest.java
@@ -0,0 +1,89 @@
+package org.bukkit;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import org.bukkit.craftbukkit.util.CraftLegacy;
+import org.bukkit.material.MaterialData;
+import org.bukkit.support.AbstractTestingBase;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class LegacyTest extends AbstractTestingBase {
+
+ private final Set<Material> INVALIDATED_MATERIALS = new HashSet<>(Arrays.asList(Material.ACACIA_BUTTON, Material.ACACIA_PRESSURE_PLATE, Material.ACACIA_TRAPDOOR, Material.AIR, Material.ATTACHED_MELON_STEM, Material.ATTACHED_PUMPKIN_STEM,
+ Material.BIRCH_BUTTON, Material.BIRCH_PRESSURE_PLATE, Material.BIRCH_TRAPDOOR, Material.BLACK_WALL_BANNER, Material.BLUE_WALL_BANNER, Material.BROWN_WALL_BANNER, Material.BUBBLE_COLUMN, Material.CAVE_AIR, Material.CREEPER_WALL_HEAD,
+ Material.CYAN_WALL_BANNER, Material.DARK_OAK_BUTTON, Material.DARK_OAK_PRESSURE_PLATE, Material.DARK_OAK_TRAPDOOR, Material.DARK_PRISMARINE_SLAB, Material.DARK_PRISMARINE_STAIRS, Material.DEBUG_STICK, Material.DONKEY_SPAWN_EGG,
+ Material.DRAGON_WALL_HEAD, Material.DRIED_KELP, Material.DRIED_KELP_BLOCK, Material.ELDER_GUARDIAN_SPAWN_EGG, Material.EVOKER_SPAWN_EGG, Material.GRAY_WALL_BANNER, Material.GREEN_WALL_BANNER, Material.HUSK_SPAWN_EGG,
+ Material.JUNGLE_BUTTON, Material.JUNGLE_PRESSURE_PLATE, Material.JUNGLE_TRAPDOOR, Material.KELP, Material.KELP_PLANT, Material.LIGHT_BLUE_WALL_BANNER, Material.LIGHT_GRAY_WALL_BANNER, Material.LIME_WALL_BANNER, Material.LLAMA_SPAWN_EGG,
+ Material.MAGENTA_WALL_BANNER, Material.MULE_SPAWN_EGG, Material.ORANGE_WALL_BANNER, Material.PARROT_SPAWN_EGG, Material.PHANTOM_SPAWN_EGG, Material.PINK_WALL_BANNER, Material.PLAYER_WALL_HEAD, Material.POLAR_BEAR_SPAWN_EGG,
+ Material.POTTED_ACACIA_SAPLING, Material.POTTED_ALLIUM, Material.POTTED_AZURE_BLUET, Material.POTTED_BIRCH_SAPLING, Material.POTTED_BLUE_ORCHID, Material.POTTED_BROWN_MUSHROOM, Material.POTTED_DANDELION, Material.POTTED_DARK_OAK_SAPLING,
+ Material.POTTED_DEAD_BUSH, Material.POTTED_FERN, Material.POTTED_JUNGLE_SAPLING, Material.POTTED_OAK_SAPLING, Material.POTTED_ORANGE_TULIP, Material.POTTED_OXEYE_DAISY, Material.POTTED_PINK_TULIP, Material.POTTED_POPPY,
+ Material.POTTED_RED_MUSHROOM, Material.POTTED_RED_TULIP, Material.POTTED_SPRUCE_SAPLING, Material.POTTED_WHITE_TULIP, Material.PRISMARINE_BRICK_SLAB, Material.PRISMARINE_BRICK_STAIRS, Material.PRISMARINE_SLAB, Material.PRISMARINE_STAIRS,
+ Material.PUMPKIN, Material.PURPLE_WALL_BANNER, Material.RED_WALL_BANNER, Material.SEAGRASS, Material.SKELETON_HORSE_SPAWN_EGG, Material.SKELETON_WALL_SKULL, Material.SPRUCE_BUTTON, Material.SPRUCE_PRESSURE_PLATE, Material.SPRUCE_TRAPDOOR,
+ Material.STRAY_SPAWN_EGG, Material.STRIPPED_ACACIA_LOG, Material.STRIPPED_BIRCH_LOG, Material.STRIPPED_DARK_OAK_LOG, Material.STRIPPED_JUNGLE_LOG, Material.STRIPPED_OAK_LOG, Material.STRIPPED_SPRUCE_LOG, Material.TALL_SEAGRASS,
+ Material.TRIDENT, Material.TURTLE_EGG, Material.TURTLE_HELMET, Material.SCUTE, Material.TURTLE_SPAWN_EGG, Material.VEX_SPAWN_EGG, Material.VINDICATOR_SPAWN_EGG, Material.VOID_AIR, Material.WHITE_BED,
+ Material.WITHER_SKELETON_SPAWN_EGG, Material.WITHER_SKELETON_WALL_SKULL, Material.YELLOW_WALL_BANNER, Material.ZOMBIE_HORSE_SPAWN_EGG, Material.ZOMBIE_VILLAGER_SPAWN_EGG, Material.ZOMBIE_WALL_HEAD,
+ Material.COD_BUCKET, Material.COD_SPAWN_EGG, Material.PUFFERFISH_BUCKET, Material.PUFFERFISH_SPAWN_EGG, Material.SALMON_BUCKET, Material.SALMON_SPAWN_EGG,
+ Material.TROPICAL_FISH_BUCKET, Material.DROWNED_SPAWN_EGG, Material.SHULKER_BOX, Material.TROPICAL_FISH_SPAWN_EGG,
+ Material.BLUE_ICE, Material.BRAIN_CORAL, Material.BRAIN_CORAL_BLOCK, Material.BRAIN_CORAL_FAN, Material.BUBBLE_CORAL, Material.BUBBLE_CORAL_BLOCK, Material.BUBBLE_CORAL_FAN, Material.CONDUIT, Material.DEAD_BRAIN_CORAL_BLOCK,
+ Material.DEAD_BUBBLE_CORAL_BLOCK, Material.DEAD_FIRE_CORAL_BLOCK, Material.DEAD_HORN_CORAL_BLOCK, Material.DEAD_TUBE_CORAL_BLOCK, Material.DOLPHIN_SPAWN_EGG, Material.FIRE_CORAL, Material.FIRE_CORAL_BLOCK, Material.FIRE_CORAL_FAN,
+ Material.HEART_OF_THE_SEA, Material.HORN_CORAL, Material.HORN_CORAL_BLOCK, Material.HORN_CORAL_FAN, Material.NAUTILUS_SHELL, Material.PHANTOM_MEMBRANE, Material.SEA_PICKLE, Material.TUBE_CORAL, Material.TUBE_CORAL_BLOCK,
+ Material.TUBE_CORAL_FAN, Material.STRIPPED_ACACIA_WOOD, Material.STRIPPED_BIRCH_WOOD, Material.STRIPPED_DARK_OAK_WOOD, Material.STRIPPED_JUNGLE_WOOD, Material.STRIPPED_OAK_WOOD, Material.STRIPPED_SPRUCE_WOOD,
+ Material.ACACIA_WOOD, Material.BIRCH_WOOD, Material.DARK_OAK_WOOD, Material.JUNGLE_WOOD, Material.OAK_WOOD, Material.SPRUCE_WOOD,
+ //
+ Material.LEGACY_AIR, Material.LEGACY_DEAD_BUSH, Material.LEGACY_BURNING_FURNACE, Material.LEGACY_WALL_SIGN, Material.LEGACY_REDSTONE_TORCH_OFF, Material.LEGACY_SKULL, Material.LEGACY_REDSTONE_COMPARATOR_ON, Material.LEGACY_WALL_BANNER, Material.LEGACY_MONSTER_EGG));
+
+ private final Set<Material> INVERSION_FAILS = new HashSet<>(Arrays.asList(Material.LEGACY_DOUBLE_STEP, Material.LEGACY_GLOWING_REDSTONE_ORE, Material.LEGACY_DIODE_BLOCK_ON, Material.LEGACY_REDSTONE_LAMP_ON, Material.LEGACY_WOOD_DOUBLE_STEP,
+ Material.LEGACY_DAYLIGHT_DETECTOR_INVERTED, Material.LEGACY_DOUBLE_STONE_SLAB2, Material.LEGACY_PURPUR_DOUBLE_SLAB, Material.LEGACY_WHEAT, Material.LEGACY_SIGN, Material.LEGACY_WOOD_DOOR, Material.LEGACY_IRON_DOOR, Material.LEGACY_SUGAR_CANE,
+ Material.LEGACY_CAKE, Material.LEGACY_BED, Material.LEGACY_DIODE, Material.LEGACY_NETHER_STALK, Material.LEGACY_BREWING_STAND_ITEM, Material.LEGACY_CAULDRON_ITEM, Material.LEGACY_REDSTONE_COMPARATOR, Material.LEGACY_SPRUCE_DOOR_ITEM,
+ Material.LEGACY_BIRCH_DOOR_ITEM, Material.LEGACY_JUNGLE_DOOR_ITEM, Material.LEGACY_ACACIA_DOOR_ITEM, Material.LEGACY_DARK_OAK_DOOR_ITEM, Material.LEGACY_STATIONARY_LAVA, Material.LEGACY_STATIONARY_WATER));
+
+ @Test
+ public void toLegacyMaterial() {
+ for (Material material : Material.values()) {
+ if (!INVALIDATED_MATERIALS.contains(material) && !material.isLegacy()) {
+ MaterialData converted = CraftLegacy.toLegacyData(material);
+
+ Assert.assertNotEquals("Could not toLegacy " + material, Material.LEGACY_AIR, converted.getItemType());
+
+ if (!INVALIDATED_MATERIALS.contains(converted.getItemType())) {
+ Assert.assertNotEquals("Could not fromLegacy(toLegacy) " + converted + "(" + material + ")", Material.AIR, CraftLegacy.fromLegacy(converted));
+ }
+ if (!INVERSION_FAILS.contains(material)) {
+ Assert.assertEquals("Could not fromLegacy(toLegacy) " + converted + "(" + material + ")", material, CraftLegacy.fromLegacy(converted));
+ }
+ }
+ }
+
+ Assert.assertEquals("Could not toLegacy Air", Material.LEGACY_AIR, CraftLegacy.toLegacy(Material.AIR));
+ }
+
+ @Test
+ public void fromLegacyMaterial() {
+ for (Material material : Material.values()) {
+ if (!INVALIDATED_MATERIALS.contains(material) && material.isLegacy()) {
+ Material converted = CraftLegacy.fromLegacy(material);
+ Assert.assertNotEquals("Could not fromLegacy " + material, Material.AIR, converted);
+
+ Assert.assertNotEquals("Could not toLegacy(fromLegacy) " + converted + "(" + material + ")", Material.AIR, CraftLegacy.toLegacy(converted));
+ if (!INVERSION_FAILS.contains(material)) {
+ Assert.assertEquals("Could not toLegacy(fromLegacy) " + converted + "(" + material + ")", material, CraftLegacy.toLegacy(converted));
+ }
+ }
+ }
+
+ Assert.assertEquals("Could not fromLegacy Air", Material.AIR, CraftLegacy.fromLegacy(Material.LEGACY_AIR));
+ }
+
+ @Test
+ public void testRestricted() {
+ for (Material material : CraftLegacy.values()) {
+ Assert.assertTrue("Must iterate only legacy materials", material.isLegacy());
+ }
+
+ for (Material material : CraftLegacy.modern_values()) {
+ Assert.assertFalse("Must iterate only modern materials", material.isLegacy());
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/MaterialTest.java b/src/test/java/org/bukkit/MaterialTest.java
index a9b4e525..be0690f3 100644
--- a/src/test/java/org/bukkit/MaterialTest.java
+++ b/src/test/java/org/bukkit/MaterialTest.java
@@ -7,6 +7,7 @@ import java.util.Collections;
import java.util.Map;
import net.minecraft.server.Item;
+import net.minecraft.server.MinecraftKey;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
@@ -19,13 +20,13 @@ public class MaterialTest extends AbstractTestingBase {
@Test
public void verifyMapping() {
- Map<Integer, Material> materials = Maps.newHashMap();
+ Map<MinecraftKey, Material> materials = Maps.newHashMap();
for (Material material : Material.values()) {
if (INVALIDATED_MATERIALS.contains(material)) {
continue;
}
- materials.put(material.getId(), material);
+ materials.put(CraftMagicNumbers.key(material), material);
}
Iterator<Item> items = Item.REGISTRY.iterator();
@@ -34,12 +35,13 @@ public class MaterialTest extends AbstractTestingBase {
Item item = items.next();
if (item == null) continue;
- int id = CraftMagicNumbers.getId(item);
+ MinecraftKey id = Item.REGISTRY.b(item);
String name = item.getName();
Material material = materials.remove(id);
assertThat("Missing " + name + "(" + id + ")", material, is(not(nullValue())));
+ assertNotNull("No item mapping for " + name, CraftMagicNumbers.getMaterial(item));
}
assertThat(materials, is(Collections.EMPTY_MAP));
diff --git a/src/test/java/org/bukkit/ParticleTest.java b/src/test/java/org/bukkit/ParticleTest.java
index c00869ba..c0cb4a1e 100644
--- a/src/test/java/org/bukkit/ParticleTest.java
+++ b/src/test/java/org/bukkit/ParticleTest.java
@@ -1,19 +1,34 @@
package org.bukkit;
-import net.minecraft.server.EnumParticle;
+import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.CraftParticle;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.material.MaterialData;
+import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert;
import org.junit.Test;
-public class ParticleTest {
+public class ParticleTest extends AbstractTestingBase {
@Test
public void verifyMapping() {
for (Particle bukkit : Particle.values()) {
- Assert.assertNotNull("Missing Bukkit->NMS particle mapping", CraftParticle.toNMS(bukkit));
+ Object data = null;
+ if (bukkit.getDataType().equals(ItemStack.class)) {
+ data = new ItemStack(Material.STONE);
+ } else if (bukkit.getDataType() == MaterialData.class) {
+ data = new MaterialData(Material.LEGACY_STONE);
+ } else if (bukkit.getDataType() == Particle.DustOptions.class) {
+ data = new Particle.DustOptions(Color.BLACK, 0);
+ } else if (bukkit.getDataType() == BlockData.class) {
+ data = CraftBlockData.newData(Material.STONE, "");
+ }
+
+ Assert.assertNotNull("Missing Bukkit->NMS particle mapping for " + bukkit, CraftParticle.toNMS(bukkit, data));
}
- for (EnumParticle nms : EnumParticle.values()) {
- Assert.assertNotNull("Missing NMS->Bukkit particle mapping", CraftParticle.toBukkit(nms));
+ for (net.minecraft.server.Particle nms : (Iterable<net.minecraft.server.Particle<?>>) net.minecraft.server.Particle.REGISTRY) { // Eclipse fail
+ Assert.assertNotNull("Missing NMS->Bukkit particle mapping for " + nms, CraftParticle.toBukkit(nms));
}
}
}
diff --git a/src/test/java/org/bukkit/PerMaterialTest.java b/src/test/java/org/bukkit/PerMaterialTest.java
index ed5242a9..dfa24769 100644
--- a/src/test/java/org/bukkit/PerMaterialTest.java
+++ b/src/test/java/org/bukkit/PerMaterialTest.java
@@ -43,7 +43,9 @@ public class PerMaterialTest extends AbstractTestingBase {
public static List<Object[]> data() {
List<Object[]> list = Lists.newArrayList();
for (Material material : Material.values()) {
- list.add(new Object[] {material});
+ if (!material.isLegacy()) {
+ list.add(new Object[] {material});
+ }
}
return list;
}
@@ -51,6 +53,13 @@ public class PerMaterialTest extends AbstractTestingBase {
@Parameter public Material material;
@Test
+ public void isBlock() {
+ if (material != Material.AIR && material != Material.CAVE_AIR && material != Material.VOID_AIR) {
+ assertThat(material.isBlock(), is(not(CraftMagicNumbers.getBlock(material).getBlockData().isAir())));
+ }
+ }
+
+ @Test
public void isSolid() {
if (material == Material.AIR) {
assertFalse(material.isSolid());
@@ -106,7 +115,7 @@ public class PerMaterialTest extends AbstractTestingBase {
if (material == Material.AIR) {
assertTrue(material.isTransparent());
} else if (material.isBlock()) {
- assertThat(material.isTransparent(), is(not(CraftMagicNumbers.getBlock(material).getBlockData().getMaterial().blocksLight())));
+ // assertThat(material.isTransparent(), is(not(CraftMagicNumbers.getBlock(material).getBlockData().getMaterial().blocksLight()))); // PAIL: not unit testable anymore (17w50a)
} else {
assertFalse(material.isTransparent());
}
@@ -164,6 +173,15 @@ public class PerMaterialTest extends AbstractTestingBase {
}
@Test
+ public void testDurability() {
+ if (!material.isBlock()) {
+ assertThat(material.getMaxDurability(), is((short) CraftMagicNumbers.getItem(material).getMaxDurability()));
+ } else {
+ assertThat(material.getMaxDurability(), is((short) 0));
+ }
+ }
+
+ @Test
public void testBlock() {
if (material == Material.AIR) {
assertTrue(material.isBlock());
diff --git a/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java b/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java
index e05e7330..055bc426 100644
--- a/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java
+++ b/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java
@@ -3,10 +3,13 @@ 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.EntityTypes;
+import net.minecraft.server.Item;
import net.minecraft.server.StatisticList;
+import net.minecraft.server.StatisticWrapper;
+import org.bukkit.entity.EntityType;
import org.bukkit.craftbukkit.CraftStatistic;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
@@ -17,17 +20,38 @@ public class StatisticsAndAchievementsTest extends AbstractTestingBase {
@Test
@SuppressWarnings("unchecked")
+ public void verifyEntityMapping() throws Throwable {
+ for (Statistic statistic : Statistic.values()) {
+ if (statistic.getType() == Statistic.Type.ENTITY) {
+ for (EntityType entity : EntityType.values()) {
+ if (entity.getName() != null) {
+ assertNotNull(statistic + " missing for " + entity, CraftStatistic.getEntityStatistic(statistic, entity));
+ }
+ }
+ }
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
public void verifyStatisticMapping() throws Throwable {
HashMultiset<Statistic> statistics = HashMultiset.create();
- for (net.minecraft.server.Statistic statistic : (List<net.minecraft.server.Statistic>) StatisticList.stats) {
- String name = statistic.name;
-
- String message = String.format("org.bukkit.Statistic is missing: '%s'", name);
-
- Statistic subject = CraftStatistic.getBukkitStatistic(statistic);
- assertThat(message, subject, is(not(nullValue())));
-
- statistics.add(subject);
+ for (StatisticWrapper wrapper : (Iterable<StatisticWrapper<?>>) StatisticList.REGISTRY) { // Eclipse fail
+ for (Object child : wrapper.a()) {
+ net.minecraft.server.Statistic<?> statistic = wrapper.b(child);
+ String message = String.format("org.bukkit.Statistic is missing: '%s'", statistic);
+
+ Statistic subject = CraftStatistic.getBukkitStatistic(statistic);
+ assertThat(message, subject, is(not(nullValue())));
+
+ if (wrapper.a() == Block.REGISTRY || wrapper.a() == Item.REGISTRY) {
+ assertNotNull("Material type map missing for " + child, CraftStatistic.getMaterialFromStatistic(statistic));
+ } else if (wrapper.a() == EntityTypes.REGISTRY) {
+ assertNotNull("Entity type map missing for " + EntityTypes.getName((EntityTypes<?>) child), CraftStatistic.getEntityTypeFromStatistic((net.minecraft.server.Statistic<EntityTypes<?>>) statistic));
+ }
+
+ statistics.add(subject);
+ }
}
for (Statistic statistic : Statistic.values()) {
diff --git a/src/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java b/src/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java
index 225df40a..792e1fc6 100644
--- a/src/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java
@@ -1,32 +1,31 @@
package org.bukkit.craftbukkit.generator;
-import org.bukkit.DyeColor;
import org.bukkit.Material;
-import org.bukkit.material.MaterialData;
-import org.bukkit.material.Wool;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
import static org.junit.Assert.*;
-public class ChunkDataTest {
+public class ChunkDataTest extends AbstractTestingBase {
- private static final MaterialData RED_WOOL = new Wool(DyeColor.RED);
- private static final MaterialData AIR = new MaterialData(Material.AIR);
+ private static final BlockData RED_WOOL = Material.RED_WOOL.createBlockData();
+ private static final BlockData AIR = Material.AIR.createBlockData();
- private boolean testSetBlock(CraftChunkData data, int x, int y, int z, MaterialData type, MaterialData expected) {
+ private boolean testSetBlock(CraftChunkData data, int x, int y, int z, BlockData type, BlockData expected) {
data.setBlock(x, y, z, type);
- return expected.equals(data.getTypeAndData(x, y, z));
+ return expected.equals(data.getBlockData(x, y, z));
}
- private void testSetRegion(CraftChunkData data, int minx, int miny, int minz, int maxx, int maxy, int maxz, MaterialData type) {
+ private void testSetRegion(CraftChunkData data, int minx, int miny, int minz, int maxx, int maxy, int maxz, BlockData type) {
data.setRegion(minx, miny, minz, maxx, maxy, maxz, type);
for (int y = 0; y < data.getMaxHeight(); y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
boolean inRegion = miny <= y && y < maxy && minx <= x && x < maxx && minz <= z && z < maxz;
- if (inRegion != type.equals(data.getTypeAndData(x, y, z))) {
+ if (inRegion != type.equals(data.getBlockData(x, y, z))) {
throw new IllegalStateException(
"setRegion(" + minx + ", " + miny + ", " + minz + ", " + maxx + ", " + maxy + ", " + maxz + ", " + type + ")"
- + "-> block at " + x + ", " + y + ", " + z + " is " + data.getTypeAndData(x, y, z));
+ + "-> block at " + x + ", " + y + ", " + z + " is " + data.getBlockData(x, y, z));
}
}
}
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java b/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java
index 1349a7f1..2a0791bb 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java
@@ -6,6 +6,7 @@ import static org.hamcrest.Matchers.*;
import java.util.ArrayList;
import java.util.List;
+import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
@@ -25,23 +26,23 @@ public class CompositeSerialization extends AbstractTestingBase {
YamlConfiguration out = getConfig();
List<ItemStack> stacks = new ArrayList<ItemStack>();
- stacks.add(new ItemStack(1));
- stacks.add(new ItemStack(2));
- stacks.add(new ItemStack(3));
- stacks.add(new ItemStack(4, 17));
- stacks.add(new ItemStack(5, 63));
- stacks.add(new ItemStack(6, 1, (short) 1));
- stacks.add(new ItemStack(18, 32, (short) 2));
-
- ItemStack item7 = new ItemStack(256);
- item7.addUnsafeEnchantment(Enchantment.getById(1), 1);
+ stacks.add(new ItemStack(Material.STONE));
+ stacks.add(new ItemStack(Material.GRASS));
+ stacks.add(new ItemStack(Material.DIRT));
+ stacks.add(new ItemStack(Material.COBBLESTONE, 17));
+ stacks.add(new ItemStack(Material.OAK_PLANKS, 63));
+ stacks.add(new ItemStack(Material.OAK_SAPLING, 1, (short) 1));
+ stacks.add(new ItemStack(Material.OAK_LEAVES, 32, (short) 2));
+
+ ItemStack item7 = new ItemStack(Material.IRON_SHOVEL);
+ item7.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 1);
stacks.add(item7);
- ItemStack item8 = new ItemStack(257);
- item8.addUnsafeEnchantment(Enchantment.getById(2), 2);
- item8.addUnsafeEnchantment(Enchantment.getById(3), 1);
- item8.addUnsafeEnchantment(Enchantment.getById(4), 5);
- item8.addUnsafeEnchantment(Enchantment.getById(5), 4);
+ ItemStack item8 = new ItemStack(Material.IRON_PICKAXE);
+ item8.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 2);
+ item8.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 1);
+ item8.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 5);
+ item8.addUnsafeEnchantment(Enchantment.OXYGEN, 4);
stacks.add(item8);
out.set("composite-list.abc.def", stacks);
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemFactoryTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemFactoryTest.java
index f5bcbdbe..18f3e1ff 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemFactoryTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemFactoryTest.java
@@ -10,7 +10,7 @@ import java.util.HashSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-import net.minecraft.server.CommandAbstract;
+import net.minecraft.server.IAnimal;
import net.minecraft.server.IAttribute;
import org.bukkit.support.AbstractTestingBase;
@@ -20,7 +20,7 @@ public class ItemFactoryTest extends AbstractTestingBase {
@Test
public void testKnownAttributes() throws Throwable {
- final ZipInputStream nmsZipStream = new ZipInputStream(CommandAbstract.class/* Magic class that isn't imported! */.getProtectionDomain().getCodeSource().getLocation().openStream());
+ final ZipInputStream nmsZipStream = new ZipInputStream(IAnimal.class/* Magic class that isn't imported! */.getProtectionDomain().getCodeSource().getLocation().openStream());
final Collection<String> names = new HashSet<String>();
for (ZipEntry clazzEntry; (clazzEntry = nmsZipStream.getNextEntry()) != null; ) {
final String entryName = clazzEntry.getName();
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
index 1f537d58..74e37cd9 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
@@ -3,13 +3,14 @@ package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.server.Block;
import net.minecraft.server.ITileEntity;
import net.minecraft.server.Item;
import net.minecraft.server.ItemBlock;
-import net.minecraft.server.ItemReed;
+import net.minecraft.server.ItemBlockWallable;
import org.bukkit.Bukkit;
import org.bukkit.Color;
@@ -26,6 +27,7 @@ import org.bukkit.craftbukkit.inventory.ItemStackTest.BukkitWrapper;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CraftWrapper;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
+import org.bukkit.entity.TropicalFish;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.BlockStateMeta;
@@ -39,6 +41,7 @@ import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SpawnEggMeta;
+import org.bukkit.inventory.meta.TropicalFishBucketMeta;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
@@ -125,12 +128,12 @@ public class ItemMetaTest extends AbstractTestingBase {
}
private static FireworkMeta newFireworkMeta() {
- return ((FireworkMeta) Bukkit.getItemFactory().getItemMeta(Material.FIREWORK));
+ return ((FireworkMeta) Bukkit.getItemFactory().getItemMeta(Material.FIREWORK_ROCKET));
}
@Test
public void testCrazyEquality() {
- CraftItemStack craft = CraftItemStack.asCraftCopy(new ItemStack(1));
+ CraftItemStack craft = CraftItemStack.asCraftCopy(new ItemStack(Material.STONE));
craft.setItemMeta(craft.getItemMeta());
ItemStack bukkit = new ItemStack(craft);
assertThat(craft, is(bukkit));
@@ -139,21 +142,24 @@ public class ItemMetaTest extends AbstractTestingBase {
@Test
public void testBlockStateMeta() {
- for (Item item : (Iterable<Item>) Item.REGISTRY) {
- Block block = null;
+ List<Block> queue = new ArrayList<>();
+ for (Item item : (Iterable<Item>) Item.REGISTRY) { // Eclipse fail
if (item instanceof ItemBlock) {
- block = ((ItemBlock) item).getBlock();
- } else if (item instanceof ItemReed) {
- block = ((ItemReed) item).a;
+ queue.add(((ItemBlock) item).getBlock());
}
+ if (item instanceof ItemBlockWallable) {
+ queue.add(((ItemBlockWallable) item).wallBlock);
+ }
+ }
+ for (Block block : queue) {
if (block != null) {
if (block instanceof ITileEntity) {
ItemStack stack = CraftItemStack.asNewCraftStack(Item.getItemOf(block));
// Command blocks aren't unit testable atm
- if (stack.getType() == Material.AIR || stack.getType() == Material.COMMAND || stack.getType() == Material.COMMAND_CHAIN || stack.getType() == Material.COMMAND_REPEATING) {
+ if (stack.getType() == Material.COMMAND_BLOCK || stack.getType() == Material.CHAIN_COMMAND_BLOCK || stack.getType() == Material.REPEATING_COMMAND_BLOCK) {
return;
}
@@ -172,7 +178,7 @@ public class ItemMetaTest extends AbstractTestingBase {
@Test
public void testEachExtraData() {
final List<StackProvider> providers = Arrays.asList(
- new StackProvider(Material.BOOK_AND_QUILL) {
+ new StackProvider(Material.WRITABLE_BOOK) {
@Override ItemStack operate(final ItemStack cleanStack) {
final BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setAuthor("Some author");
@@ -202,7 +208,7 @@ public class ItemMetaTest extends AbstractTestingBase {
}
},
*/
- new StackProvider(Material.MAP) {
+ new StackProvider(Material.FILLED_MAP) {
@Override ItemStack operate(final ItemStack cleanStack) {
final MapMeta meta = (MapMeta) cleanStack.getItemMeta();
meta.setScaling(true);
@@ -227,7 +233,7 @@ public class ItemMetaTest extends AbstractTestingBase {
return cleanStack;
}
},
- new StackProvider(Material.FIREWORK) {
+ new StackProvider(Material.FIREWORK_ROCKET) {
@Override ItemStack operate(final ItemStack cleanStack) {
final FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.GREEN).withFade(Color.OLIVE).with(Type.BALL_LARGE).build());
@@ -243,7 +249,7 @@ public class ItemMetaTest extends AbstractTestingBase {
return cleanStack;
}
},
- new StackProvider(Material.FIREWORK_CHARGE) {
+ new StackProvider(Material.FIREWORK_STAR) {
@Override ItemStack operate(final ItemStack cleanStack) {
final FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.MAROON, Color.BLACK).with(Type.CREEPER).withFlicker().build());
@@ -251,7 +257,7 @@ public class ItemMetaTest extends AbstractTestingBase {
return cleanStack;
}
},
- new StackProvider(Material.BANNER) {
+ new StackProvider(Material.WHITE_BANNER) {
@Override ItemStack operate(ItemStack cleanStack) {
final BannerMeta meta = (BannerMeta) cleanStack.getItemMeta();
meta.setBaseColor(DyeColor.CYAN);
@@ -259,26 +265,38 @@ public class ItemMetaTest extends AbstractTestingBase {
cleanStack.setItemMeta(meta);
return cleanStack;
}
- },
- new StackProvider(Material.MONSTER_EGG) {
+ },
+ /* No distinguishing features, add back with virtual entity API
+ new StackProvider(Material.ZOMBIE_SPAWN_EGG) {
@Override ItemStack operate(ItemStack cleanStack) {
final SpawnEggMeta meta = (SpawnEggMeta) cleanStack.getItemMeta();
meta.setSpawnedType(EntityType.ZOMBIE);
cleanStack.setItemMeta(meta);
return cleanStack;
- }
- },
- new StackProvider(Material.KNOWLEDGE_BOOK) {
+ }
+ },
+ */
+ new StackProvider(Material.KNOWLEDGE_BOOK) {
@Override ItemStack operate(ItemStack cleanStack) {
final KnowledgeBookMeta meta = (KnowledgeBookMeta) cleanStack.getItemMeta();
meta.addRecipe(new NamespacedKey("minecraft", "test"), new NamespacedKey("plugin", "test"));
cleanStack.setItemMeta(meta);
return cleanStack;
}
+ },
+ new StackProvider(Material.TROPICAL_FISH_BUCKET) {
+ @Override ItemStack operate(ItemStack cleanStack) {
+ final TropicalFishBucketMeta meta = (TropicalFishBucketMeta) cleanStack.getItemMeta();
+ meta.setBodyColor(DyeColor.ORANGE);
+ meta.setPatternColor(DyeColor.BLACK);
+ meta.setPattern(TropicalFish.Pattern.DASHER);
+ cleanStack.setItemMeta(meta);
+ return cleanStack;
+ }
}
);
- assertThat("Forgotten test?", providers, hasSize(ItemStackTest.COMPOUND_MATERIALS.length - 3/* Normal item meta, skulls and tile entities */));
+ assertThat("Forgotten test?", providers, hasSize(ItemStackTest.COMPOUND_MATERIALS.length - 4/* Normal item meta, skulls, eggs and tile entities */));
for (final StackProvider provider : providers) {
downCastTest(new BukkitWrapper(provider));
@@ -288,7 +306,7 @@ public class ItemMetaTest extends AbstractTestingBase {
private void downCastTest(final StackWrapper provider) {
final String name = provider.toString();
- final ItemStack blank = new ItemStack(1);
+ final ItemStack blank = new ItemStack(Material.STONE);
final ItemStack craftBlank = CraftItemStack.asCraftCopy(blank);
downCastTest(name, provider.stack(), blank);
@@ -304,7 +322,7 @@ public class ItemMetaTest extends AbstractTestingBase {
assertThat(name, stack, is(not(blank)));
assertThat(name, stack.getItemMeta(), is(not(blank.getItemMeta())));
- stack.setTypeId(1);
+ stack.setType(Material.STONE);
assertThat(name, stack, is(blank));
}
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackBookTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackBookTest.java
index a7edc048..c16c5611 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackBookTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackBookTest.java
@@ -17,7 +17,7 @@ public class ItemStackBookTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
- return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.WRITTEN_BOOK, Material.BOOK_AND_QUILL);
+ return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.WRITTEN_BOOK, Material.WRITABLE_BOOK);
}
@SuppressWarnings("unchecked")
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkChargeTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkChargeTest.java
index cb38cd27..fbfce58c 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkChargeTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkChargeTest.java
@@ -20,7 +20,7 @@ public class ItemStackFireworkChargeTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
- return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_CHARGE);
+ return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_STAR);
}
@SuppressWarnings("unchecked")
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkTest.java
index 40b1d19d..55e6629b 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackFireworkTest.java
@@ -20,7 +20,7 @@ public class ItemStackFireworkTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
- return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK);
+ return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_ROCKET);
}
@SuppressWarnings("unchecked")
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackMapTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackMapTest.java
index 9c499858..c13f6d57 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackMapTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackMapTest.java
@@ -17,7 +17,7 @@ public class ItemStackMapTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
- return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.MAP);
+ return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FILLED_MAP);
}
@SuppressWarnings("unchecked")
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackSkullTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackSkullTest.java
index a79d443e..1561bf88 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackSkullTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemStackSkullTest.java
@@ -17,7 +17,7 @@ public class ItemStackSkullTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
- return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.SKULL_ITEM);
+ return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.PLAYER_HEAD);
}
@SuppressWarnings("unchecked")
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/NMSCraftItemStackTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/NMSCraftItemStackTest.java
index 1f5a6a32..5a43fd86 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/NMSCraftItemStackTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/NMSCraftItemStackTest.java
@@ -21,7 +21,6 @@ public class NMSCraftItemStackTest extends AbstractTestingBase {
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));
}
diff --git a/src/test/java/org/bukkit/entity/EntityTypesTest.java b/src/test/java/org/bukkit/entity/EntityTypesTest.java
new file mode 100644
index 00000000..d8c3b013
--- /dev/null
+++ b/src/test/java/org/bukkit/entity/EntityTypesTest.java
@@ -0,0 +1,29 @@
+package org.bukkit.entity;
+
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+import net.minecraft.server.EntityTypes;
+import net.minecraft.server.MinecraftKey;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class EntityTypesTest {
+
+ @Test
+ public void testMaps() {
+ Set<EntityType> allBukkit = Arrays.stream(EntityType.values()).filter((b) -> b.getName() != null).collect(Collectors.toSet());
+
+ for (Object o : EntityTypes.REGISTRY) {
+ EntityTypes<?> nms = (EntityTypes<?>) o; // Eclipse fail
+ MinecraftKey key = EntityTypes.getName(nms);
+
+ EntityType bukkit = EntityType.fromName(key.getKey());
+ Assert.assertNotNull("Missing nms->bukkit " + key, bukkit);
+
+ Assert.assertTrue("Duplicate entity nms->" + bukkit, allBukkit.remove(bukkit));
+ }
+
+ Assert.assertTrue("Unmapped bukkit entities " + allBukkit, allBukkit.isEmpty());
+ }
+}
diff --git a/src/test/java/org/bukkit/entity/TropicalFishTest.java b/src/test/java/org/bukkit/entity/TropicalFishTest.java
new file mode 100644
index 00000000..63ddb467
--- /dev/null
+++ b/src/test/java/org/bukkit/entity/TropicalFishTest.java
@@ -0,0 +1,45 @@
+package org.bukkit.entity;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.Matchers.*;
+import org.bukkit.DyeColor;
+import org.bukkit.craftbukkit.entity.CraftTropicalFish;
+import org.bukkit.entity.TropicalFish.Pattern;
+
+import org.junit.Test;
+
+public class TropicalFishTest {
+
+ @Test
+ public void testVariants() {
+ testVariant(65536, DyeColor.ORANGE, DyeColor.WHITE, Pattern.KOB);
+ testVariant(917504, DyeColor.RED, DyeColor.WHITE, Pattern.KOB);
+ testVariant(918273, DyeColor.RED, DyeColor.WHITE, Pattern.BLOCKFISH);
+ testVariant(918529, DyeColor.RED, DyeColor.WHITE, Pattern.BETTY);
+ testVariant(16778497, DyeColor.WHITE, DyeColor.ORANGE, Pattern.CLAYFISH);
+ testVariant(50660352, DyeColor.LIME, DyeColor.LIGHT_BLUE, Pattern.BRINELY);
+ testVariant(50726144, DyeColor.PINK, DyeColor.LIGHT_BLUE, Pattern.SPOTTY);
+ testVariant(50790656, DyeColor.GRAY, DyeColor.LIGHT_BLUE, Pattern.SUNSTREAK);
+ testVariant(67108865, DyeColor.WHITE, DyeColor.YELLOW, Pattern.FLOPPER);
+ testVariant(67110144, DyeColor.WHITE, DyeColor.YELLOW, Pattern.SPOTTY);
+ testVariant(67371265, DyeColor.YELLOW, DyeColor.YELLOW, Pattern.STRIPEY);
+ testVariant(67764993, DyeColor.PURPLE, DyeColor.YELLOW, Pattern.BLOCKFISH);
+ testVariant(101253888, DyeColor.CYAN, DyeColor.PINK, Pattern.DASHER);
+ testVariant(117441025, DyeColor.WHITE, DyeColor.GRAY, Pattern.GLITTER);
+ testVariant(117441280, DyeColor.WHITE, DyeColor.GRAY, Pattern.DASHER);
+ testVariant(117441536, DyeColor.WHITE, DyeColor.GRAY, Pattern.BRINELY);
+ testVariant(117506305, DyeColor.ORANGE, DyeColor.GRAY, Pattern.STRIPEY);
+ testVariant(117899265, DyeColor.GRAY, DyeColor.GRAY, Pattern.FLOPPER);
+ testVariant(118161664, DyeColor.BLUE, DyeColor.GRAY, Pattern.SUNSTREAK);
+ testVariant(134217984, DyeColor.WHITE, DyeColor.SILVER, Pattern.SUNSTREAK);
+ testVariant(234882305, DyeColor.WHITE, DyeColor.RED, Pattern.CLAYFISH);
+ testVariant(235340288, DyeColor.GRAY, DyeColor.RED, Pattern.SNOOPER);
+ }
+
+ private void testVariant(int variant, DyeColor bodyColor, DyeColor patternColor, Pattern pattern) {
+ assertThat("variant write", CraftTropicalFish.getData(patternColor, bodyColor, pattern), is(variant));
+ assertThat("pattern colour read", CraftTropicalFish.getPatternColor(variant), is(patternColor));
+ assertThat("body colour read", CraftTropicalFish.getBodyColor(variant), is(bodyColor));
+ assertThat("pattern read", CraftTropicalFish.getPattern(variant), is(pattern));
+ }
+}
diff --git a/src/test/java/org/bukkit/map/MapTest.java b/src/test/java/org/bukkit/map/MapTest.java
index f4788a18..2dde26d3 100644
--- a/src/test/java/org/bukkit/map/MapTest.java
+++ b/src/test/java/org/bukkit/map/MapTest.java
@@ -24,7 +24,7 @@ public class MapTest {
if (nmsColors[i] == null) {
break;
}
- int rgb = nmsColors[i].ac;
+ int rgb = nmsColors[i].rgb;
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
diff --git a/src/test/java/org/bukkit/potion/PotionTest.java b/src/test/java/org/bukkit/potion/PotionTest.java
index e46429a5..74ed926f 100644
--- a/src/test/java/org/bukkit/potion/PotionTest.java
+++ b/src/test/java/org/bukkit/potion/PotionTest.java
@@ -30,6 +30,6 @@ public class PotionTest extends AbstractTestingBase {
effects.put(enumType, enumType.name());
}
- assertEquals(effects.entrySet().size(), PotionType.values().length - /* PotionTypes with no Effects */ 5);
+ assertEquals(effects.entrySet().size(), PotionType.values().length - /* PotionTypes with no/shared Effects */ 6);
}
}
diff --git a/src/test/java/org/bukkit/support/AbstractTestingBase.java b/src/test/java/org/bukkit/support/AbstractTestingBase.java
index 86c2b971..6266dc32 100644
--- a/src/test/java/org/bukkit/support/AbstractTestingBase.java
+++ b/src/test/java/org/bukkit/support/AbstractTestingBase.java
@@ -1,10 +1,16 @@
package org.bukkit.support;
import com.google.common.collect.ImmutableList;
+import java.util.Collections;
import java.util.List;
import net.minecraft.server.DispenserRegistry;
+import net.minecraft.server.EnumResourcePackType;
+import net.minecraft.server.ResourceManager;
+import net.minecraft.server.ResourcePackVanilla;
+import net.minecraft.server.TagRegistry;
import org.bukkit.Material;
-import org.junit.BeforeClass;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+import org.junit.Assert;
/**
* If you are getting: java.lang.ExceptionInInitializerError
@@ -15,67 +21,28 @@ import org.junit.BeforeClass;
* extend this class to solve it.
*/
public abstract class AbstractTestingBase {
- public static final List<Material> INVALIDATED_MATERIALS = ImmutableList.<Material>builder()
- .add(
- Material.BREWING_STAND,
- Material.BED_BLOCK,
- Material.NETHER_WARTS,
- Material.CAULDRON,
- Material.FLOWER_POT,
- Material.CROPS,
- Material.SUGAR_CANE_BLOCK,
- Material.CAKE_BLOCK,
- Material.SKULL,
- Material.PISTON_EXTENSION,
- Material.PISTON_MOVING_PIECE,
- Material.GLOWING_REDSTONE_ORE,
- Material.DIODE_BLOCK_ON,
- Material.PUMPKIN_STEM,
- Material.SIGN_POST,
- Material.REDSTONE_COMPARATOR_ON,
- Material.TRIPWIRE,
- Material.REDSTONE_LAMP_ON,
- Material.MELON_STEM,
- Material.REDSTONE_TORCH_OFF,
- Material.REDSTONE_COMPARATOR_OFF,
- Material.REDSTONE_WIRE,
- Material.WALL_SIGN,
- Material.DIODE_BLOCK_OFF,
- Material.IRON_DOOR_BLOCK,
- Material.WOODEN_DOOR,
- Material.WATER,
- Material.STATIONARY_WATER,
- Material.LAVA,
- Material.STATIONARY_LAVA,
- Material.DOUBLE_STEP,
- Material.DOUBLE_STEP,
- Material.FIRE,
- Material.PORTAL,
- Material.ENDER_PORTAL,
- Material.WOOD_DOUBLE_STEP,
- Material.COCOA,
- Material.CARROT,
- Material.POTATO,
- Material.STANDING_BANNER,
- Material.WALL_BANNER,
- Material.DAYLIGHT_DETECTOR_INVERTED,
- Material.DOUBLE_STONE_SLAB2,
- Material.SPRUCE_DOOR,
- Material.BIRCH_DOOR,
- Material.JUNGLE_DOOR,
- Material.ACACIA_DOOR,
- Material.DARK_OAK_DOOR,
- Material.PURPUR_DOUBLE_SLAB,
- Material.BEETROOT_BLOCK,
- Material.END_GATEWAY,
- Material.BURNING_FURNACE,
- Material.FROSTED_ICE
- ).build();
+ // Materials that only exist in block form (or are legacy)
+ public static final List<Material> INVALIDATED_MATERIALS;
- @BeforeClass
- public static void setup() {
+ static {
DispenserRegistry.c();
+ // Set up resource manager
+ ResourceManager resourceManager = new ResourceManager(EnumResourcePackType.SERVER_DATA);
+ // add tags for unit tests
+ resourceManager.a(new TagRegistry());
+ // Register vanilla pack
+ resourceManager.a(Collections.singletonList(new ResourcePackVanilla("minecraft")));
+
DummyServer.setup();
DummyEnchantments.setup();
+
+ ImmutableList.Builder<Material> builder = ImmutableList.builder();
+ for (Material m : Material.values()) {
+ if (m.isLegacy() || CraftMagicNumbers.getItem(m) == null) {
+ builder.add(m);
+ }
+ }
+ INVALIDATED_MATERIALS = builder.build();
+ Assert.assertTrue("Expected 533 invalidated materials (got " + INVALIDATED_MATERIALS.size() + ")", INVALIDATED_MATERIALS.size() == 533);
}
-} \ No newline at end of file
+}
diff --git a/src/test/java/org/bukkit/support/DummyServer.java b/src/test/java/org/bukkit/support/DummyServer.java
index e5215bb4..a6e7651a 100644
--- a/src/test/java/org/bukkit/support/DummyServer.java
+++ b/src/test/java/org/bukkit/support/DummyServer.java
@@ -7,8 +7,11 @@ import java.util.HashMap;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
+import org.bukkit.Material;
import org.bukkit.Server;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.inventory.CraftItemFactory;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.Versioning;
public class DummyServer implements InvocationHandler {
@@ -59,6 +62,23 @@ public class DummyServer implements InvocationHandler {
}
}
);
+ methods.put(
+ Server.class.getMethod("getUnsafe"),
+ new MethodHandler() {
+ public Object handle(DummyServer server, Object[] args) {
+ return CraftMagicNumbers.INSTANCE;
+ }
+ }
+ );
+ methods.put(
+ Server.class.getMethod("createBlockData", Material.class),
+ new MethodHandler() {
+ final Logger logger = Logger.getLogger(DummyServer.class.getCanonicalName());
+ public Object handle(DummyServer server, Object[] args) {
+ return CraftBlockData.newData((Material) args[0], null);
+ }
+ }
+ );
Bukkit.setServer(Proxy.getProxyClass(Server.class.getClassLoader(), Server.class).asSubclass(Server.class).getConstructor(InvocationHandler.class).newInstance(new DummyServer()));
} catch (Throwable t) {
throw new Error(t);