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
Enderman ender = (Enderman) e.getEntity();
BlockData m = ender.getCarriedBlock();
if (m != null && !m.getMaterial().equals(Material.AIR)) {
if (m != null && !m.getMaterial().equals(Material.AIR)) {
// Drop the item
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.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Slime;
import org.bukkit.event.entity.EntityChangeBlockEvent;
@ -65,6 +66,7 @@ public class EndermanListenerTest {
private static World world;
private static Enderman enderman;
private static Slime slime;
private BlockData bd;
@Before
public void setUp() {
@ -111,7 +113,9 @@ public class EndermanListenerTest {
enderman = mock(Enderman.class);
when(enderman.getLocation()).thenReturn(location);
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);
when(slime.getLocation()).thenReturn(location);
@ -214,7 +218,7 @@ public class EndermanListenerTest {
*/
@Test
public void testOnEndermanDeathCarryAir() {
when(enderman.getCarriedBlock()).thenReturn(Material.AIR.createBlockData());
when(bd.getMaterial()).thenReturn(Material.AIR);
EndermanListener listener = new EndermanListener();
EntityDeathEvent e = new EntityDeathEvent(enderman, new ArrayList<ItemStack>());
listener.onEndermanDeath(e);