Archiviert
13
0

Reimplement the last possible tests, add a few more

Dieser Commit ist enthalten in:
Dan Mulloy 2015-04-06 18:19:00 -04:00
Ursprung a2c9240011
Commit e31599073f
3 geänderte Dateien mit 48 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -45,7 +45,7 @@ public class WrappedBlockData extends AbstractWrapper {
FuzzyReflection fuzzy = FuzzyReflection.fromClass(BLOCK); FuzzyReflection fuzzy = FuzzyReflection.fromClass(BLOCK);
FuzzyMethodContract contract = FuzzyMethodContract.newBuilder() FuzzyMethodContract contract = FuzzyMethodContract.newBuilder()
.banModifier(Modifier.STATIC) .banModifier(Modifier.STATIC)
.parameterExactType(int.class) .parameterExactArray(int.class)
.returnTypeExact(IBLOCK_DATA) .returnTypeExact(IBLOCK_DATA)
.build(); .build();
FROM_LEGACY_DATA = Accessors.getMethodAccessor(fuzzy.getMethod(contract)); FROM_LEGACY_DATA = Accessors.getMethodAccessor(fuzzy.getMethod(contract));

Datei anzeigen

@ -28,7 +28,6 @@ public class BukkitInitialization {
* @throws IllegalAccessException If we are unable to initialize Bukkit. * @throws IllegalAccessException If we are unable to initialize Bukkit.
*/ */
public static void initializeItemMeta() throws IllegalAccessException { public static void initializeItemMeta() throws IllegalAccessException {
// None of this works in 1.8
if (!initialized) { if (!initialized) {
// Denote that we're done // Denote that we're done
initialized = true; initialized = true;

Datei anzeigen

@ -27,11 +27,15 @@ import java.lang.reflect.Array;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.minecraft.server.v1_8_R2.MobEffect;
import org.apache.commons.lang.SerializationUtils; import org.apache.commons.lang.SerializationUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.WorldType; import org.bukkit.WorldType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -40,11 +44,14 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
import com.comphenix.protocol.BukkitInitialization; import com.comphenix.protocol.BukkitInitialization;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.PacketType.Sender;
import com.comphenix.protocol.injector.PacketConstructor;
import com.comphenix.protocol.reflect.EquivalentConverter; import com.comphenix.protocol.reflect.EquivalentConverter;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.Util; import com.comphenix.protocol.utility.Util;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.BukkitConverters; import com.comphenix.protocol.wrappers.BukkitConverters;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
@ -52,6 +59,7 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.comphenix.protocol.wrappers.nbt.NbtFactory; import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.Lists;
// Ensure that the CraftItemFactory is mockable // Ensure that the CraftItemFactory is mockable
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class) @RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
@ -77,7 +85,7 @@ public class PacketContainerTest {
assertEquals(testValue, modifier.read(0)); assertEquals(testValue, modifier.read(0));
} }
/* private <T> void testObjectArray(StructureModifier<T[]> modifier, int index, T[] initialValue, T[] testValue) { private <T> void testObjectArray(StructureModifier<T[]> modifier, int index, T[] initialValue, T[] testValue) {
// Check initial value // Check initial value
assertNull(modifier.read(index)); assertNull(modifier.read(index));
modifier.writeDefaults(); modifier.writeDefaults();
@ -88,7 +96,7 @@ public class PacketContainerTest {
// Test assignment // Test assignment
modifier.write(index, testValue); modifier.write(index, testValue);
assertArrayEquals(testValue, modifier.read(0)); assertArrayEquals(testValue, modifier.read(0));
} */ }
@Test @Test
public void testGetByteArrays() { public void testGetByteArrays() {
@ -151,12 +159,18 @@ public class PacketContainerTest {
testPrimitive(explosion.getStrings(), 0, null, "hello"); testPrimitive(explosion.getStrings(), 0, null, "hello");
} }
// TODO Rewrite with chat components @Test
/* @Test
public void testGetStringArrays() { public void testGetStringArrays() {
PacketContainer explosion = new PacketContainer(PacketType.Play.Server.UPDATE_SIGN); PacketContainer tabComplete = new PacketContainer(PacketType.Play.Server.TAB_COMPLETE);
testObjectArray(explosion.getStringArrays(), 0, new String[0], new String[] { "hello", "world" }); testObjectArray(tabComplete.getStringArrays(), 0, new String[0], new String[] { "hello", "world" });
} */ }
@Test
public void testGetChatComponentArrays() {
PacketContainer signChange = new PacketContainer(PacketType.Play.Server.UPDATE_SIGN);
testObjectArray(signChange.getChatComponentArrays(), 0, new WrappedChatComponent[0],
WrappedChatComponent.fromChatMessage("hello world"));
}
@Test @Test
public void testGetIntegerArrays() { public void testGetIntegerArrays() {
@ -287,24 +301,23 @@ public class PacketContainerTest {
// @Test // @Test
// public void testGetPositionModifier() { } // public void testGetPositionModifier() { }
// TODO: Rewrite this with BlockPosition collections @Test
/* @Test
public void testGetPositionCollectionModifier() { public void testGetPositionCollectionModifier() {
PacketContainer explosionPacket = new PacketContainer(PacketType.Play.Server.EXPLOSION); PacketContainer explosionPacket = new PacketContainer(PacketType.Play.Server.EXPLOSION);
StructureModifier<List<ChunkPosition>> positionAccessor = explosionPacket.getPositionCollectionModifier(); StructureModifier<List<BlockPosition>> positionAccessor = explosionPacket.getBlockPositionCollectionModifier();
assertNull(positionAccessor.read(0)); assertNull(positionAccessor.read(0));
List<ChunkPosition> positions = Lists.newArrayList(); List<BlockPosition> positions = Lists.newArrayList();
positions.add(new ChunkPosition(1, 2, 3)); positions.add(new BlockPosition(1, 2, 3));
positions.add(new ChunkPosition(3, 4, 5)); positions.add(new BlockPosition(3, 4, 5));
// Insert and read back // Insert and read back
positionAccessor.write(0, positions); positionAccessor.write(0, positions);
List<ChunkPosition> cloned = positionAccessor.read(0); List<BlockPosition> cloned = positionAccessor.read(0);
assertEquals(positions, cloned); assertEquals(positions, cloned);
} */ }
@Test @Test
public void testGetWatchableCollectionModifier() { public void testGetWatchableCollectionModifier() {
@ -394,22 +407,36 @@ public class PacketContainerTest {
assertEquals(Material.STONE, blockAction.getBlocks().read(0)); assertEquals(Material.STONE, blockAction.getBlocks().read(0));
} }
// TODO Rewrite with MobEffects @Test
/* @Test public void testBlockData() {
PacketContainer blockChange = new PacketContainer(PacketType.Play.Server.BLOCK_CHANGE);
Material material = Material.GLOWSTONE;
WrappedBlockData data = WrappedBlockData.createData(material);
blockChange.getBlockData().write(0, data);
WrappedBlockData read = blockChange.getBlockData().read(0);
assertEquals(material, read.getType());
}
@Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testPotionEffect() { public void testPotionEffect() {
PotionEffect effect = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 60, 1); PotionEffect effect = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 60, 1);
MobEffect mobEffect = new MobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(),
effect.hasParticles());
// The constructor we want to call // The constructor we want to call
PacketConstructor creator = PacketConstructor.DEFAULT.withPacket( PacketConstructor creator = PacketConstructor.DEFAULT.withPacket(
PacketType.Play.Server.ENTITY_EFFECT, new Class<?>[] { int.class, MobEffect.class }); PacketType.Play.Server.ENTITY_EFFECT, new Class<?>[] { int.class, MobEffect.class });
PacketContainer packet = creator.createPacket(1, effect); PacketContainer packet = creator.createPacket(1, mobEffect);
assertEquals(1, (int) packet.getIntegers().read(0)); assertEquals(1, (int) packet.getIntegers().read(0));
assertEquals(effect.getType().getId(), (byte) packet.getBytes().read(0)); assertEquals(effect.getType().getId(), (byte) packet.getBytes().read(0));
assertEquals(effect.getAmplifier(), (byte) packet.getBytes().read(1)); assertEquals(effect.getAmplifier(), (byte) packet.getBytes().read(1));
assertEquals(effect.getDuration(), (short) packet.getShorts().read(0)); assertEquals(effect.getDuration(), (int) packet.getIntegers().read(1));
} */ assertEquals(effect.hasParticles(), packet.getBytes().read(2) == (effect.hasParticles() ? 1 : 0));
}
private static final List<PacketType> BLACKLISTED = Util.asList( private static final List<PacketType> BLACKLISTED = Util.asList(
PacketType.Play.Client.CUSTOM_PAYLOAD, PacketType.Play.Server.CUSTOM_PAYLOAD, PacketType.Play.Server.MAP_CHUNK PacketType.Play.Client.CUSTOM_PAYLOAD, PacketType.Play.Server.CUSTOM_PAYLOAD, PacketType.Play.Server.MAP_CHUNK