SPIGOT-2892: Fix some clone implementations and add unit test

This commit is contained in:
md_5 2017-12-16 10:18:34 +11:00
parent 2ee49b4955
commit fb4564cc37
4 changed files with 41 additions and 0 deletions

View File

@ -200,4 +200,11 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
boolean applicableTo(Material type) {
return type == Material.BANNER;
}
@Override
public CraftMetaBanner clone() {
CraftMetaBanner meta = (CraftMetaBanner) super.clone();
meta.patterns = new ArrayList<>(patterns);
return meta;
}
}

View File

@ -213,6 +213,15 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
return false;
}
@Override
public CraftMetaBlockState clone() {
CraftMetaBlockState meta = (CraftMetaBlockState) super.clone();
if (blockEntityTag != null) {
meta.blockEntityTag = blockEntityTag.g();
}
return meta;
}
@Override
public boolean hasBlockState() {
return blockEntityTag != null;

View File

@ -176,6 +176,9 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
CraftMetaSpawnEgg clone = (CraftMetaSpawnEgg) super.clone();
clone.spawnedType = spawnedType;
if (entityTag != null) {
clone.entityTag = entityTag.g();
}
return clone;
}

View File

@ -0,0 +1,22 @@
package org.bukkit.craftbukkit.inventory;
import java.lang.reflect.Method;
import org.bukkit.Material;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
public class ItemMetaCloneTest {
@Test
public void testClone() throws Throwable {
for (Material material : ItemStackTest.COMPOUND_MATERIALS) {
Class<?> clazz = CraftItemFactory.instance().getItemMeta(material).getClass();
Method clone = clazz.getDeclaredMethod("clone");
assertNotNull("Class " + clazz + " does not override clone()", clone);
assertThat("Class " + clazz + " clone return type does not match", clone.getReturnType(), is(equalTo(clazz)));
}
}
}