3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

Add isRecord and new material method tests.

Cleaned up all of the CraftBukkit tests, including moving some tests
from MaterialTest to PerMaterialTest.
Dieser Commit ist enthalten in:
Wesley Wolfe 2012-12-14 02:02:02 -06:00
Ursprung 53b064ec79
Commit 0f4c206f9b
8 geänderte Dateien mit 122 neuen und 90 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,14 +1,12 @@
package org.bukkit; package org.bukkit;
import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import net.minecraft.server.Item; import net.minecraft.server.Item;
import net.minecraft.server.ItemFood;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.Test;
@ -16,6 +14,7 @@ import org.junit.Test;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
public class MaterialTest extends AbstractTestingBase { public class MaterialTest extends AbstractTestingBase {
@Test @Test
public void verifyMapping() { public void verifyMapping() {
Map<Integer, Material> materials = Maps.newHashMap(); Map<Integer, Material> materials = Maps.newHashMap();
@ -29,40 +28,12 @@ public class MaterialTest extends AbstractTestingBase {
int id = item.id; int id = item.id;
String name = item.getName(); String name = item.getName();
int maxStackSize = item.getMaxStackSize();
int maxDurability = item.getMaxDurability();
Material material = materials.remove(id); Material material = materials.remove(id);
assertNotNull(String.format("org.bukkit.Material is missing id: %d named: %s", id, name), material); assertThat("Missing " + name + "(" + id + ")", material, is(not(nullValue())));
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)); assertThat(materials, is(Collections.EMPTY_MAP));
}
@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));
} }
} }

Datei anzeigen

@ -3,27 +3,37 @@ package org.bukkit;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.server.AchievementList;
import net.minecraft.server.Block; 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.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters; import org.junit.runners.Parameterized.Parameters;
import com.google.common.collect.Lists;
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public class PerMaterialTest { public class PerMaterialTest extends AbstractTestingBase {
static { private static int[] fireValues;
AchievementList.a();
@BeforeClass
public static void getFireValues() {
fireValues = Util.getInternalState(BlockFire.class, Block.FIRE, "a");
} }
@Parameters(name= "{index}: {0}") @Parameters(name= "{index}: {0}")
public static List<Object[]> data() { public static List<Object[]> data() {
List<Object[]> list = new ArrayList<Object[]>(); List<Object[]> list = Lists.newArrayList();
for (Material material : Material.values()) { for (Material material : Material.values()) {
list.add(new Object[] {material}); list.add(new Object[] {material});
} }
@ -42,4 +52,70 @@ public class PerMaterialTest {
assertFalse(material.isSolid()); 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());
}
}
} }

Datei anzeigen

@ -1,6 +1,7 @@
package org.bukkit; 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.bukkit.craftbukkit.CraftSound;
import org.junit.Test; import org.junit.Test;
@ -11,7 +12,7 @@ public class SoundTest {
@Test @Test
public void testGetSound() { public void testGetSound() {
for (Sound sound : Sound.values()) { for (Sound sound : Sound.values()) {
assertNotNull(sound.name(), CraftSound.getSound(sound)); assertThat(sound.name(), CraftSound.getSound(sound), is(not(nullValue())));
} }
} }
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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