Fixed EndermanListenerTest class to use BlockData properly.

This commit is contained in:
tastybento 2018-08-01 18:19:47 -04:00
parent 58288b0fa1
commit a9da00478d
2 changed files with 7 additions and 3 deletions

View File

@ -51,7 +51,7 @@ public class EndermanListener extends AbstractFlagListener {
// Get the block the enderman is holding // Get the block the enderman is holding
Enderman ender = (Enderman) e.getEntity(); Enderman ender = (Enderman) e.getEntity();
BlockData m = ender.getCarriedBlock(); BlockData m = ender.getCarriedBlock();
if (m != null && !m.getMaterial().equals(Material.AIR)) { if (m != null && !m.getMaterial().equals(Material.AIR)) {
// Drop the item // Drop the item
e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), new ItemStack(m.getMaterial())); e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), new ItemStack(m.getMaterial()));
} }

View File

@ -22,6 +22,7 @@ import org.bukkit.Material;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Enderman; import org.bukkit.entity.Enderman;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
@ -65,6 +66,7 @@ public class EndermanListenerTest {
private static World world; private static World world;
private static Enderman enderman; private static Enderman enderman;
private static Slime slime; private static Slime slime;
private BlockData bd;
@Before @Before
public void setUp() { public void setUp() {
@ -111,7 +113,9 @@ public class EndermanListenerTest {
enderman = mock(Enderman.class); enderman = mock(Enderman.class);
when(enderman.getLocation()).thenReturn(location); when(enderman.getLocation()).thenReturn(location);
when(enderman.getWorld()).thenReturn(world); when(enderman.getWorld()).thenReturn(world);
when(enderman.getCarriedBlock()).thenReturn(Material.STONE.createBlockData()); bd = mock(BlockData.class);
when(bd.getMaterial()).thenReturn(Material.STONE);
when(enderman.getCarriedBlock()).thenReturn(bd);
slime = mock(Slime.class); slime = mock(Slime.class);
when(slime.getLocation()).thenReturn(location); when(slime.getLocation()).thenReturn(location);
@ -214,7 +218,7 @@ public class EndermanListenerTest {
*/ */
@Test @Test
public void testOnEndermanDeathCarryAir() { public void testOnEndermanDeathCarryAir() {
when(enderman.getCarriedBlock()).thenReturn(Material.AIR.createBlockData()); when(bd.getMaterial()).thenReturn(Material.AIR);
EndermanListener listener = new EndermanListener(); EndermanListener listener = new EndermanListener();
EntityDeathEvent e = new EntityDeathEvent(enderman, new ArrayList<ItemStack>()); EntityDeathEvent e = new EntityDeathEvent(enderman, new ArrayList<ItemStack>());
listener.onEndermanDeath(e); listener.onEndermanDeath(e);