Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Mar 29, 2024
1 parent e8a79b4 commit 377474f
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -74,6 +75,8 @@ public class BlockProtectTest {
*/
@Before
public void setUp() throws Exception {

when(p.getWorld()).thenReturn(world);
// In World
when(addon.inWorld(world)).thenReturn(true);

Expand Down Expand Up @@ -118,11 +121,12 @@ public void testBlockProtect() {
@Test
public void testOnBlockDamage() {
ItemStack item = new ItemStack(Material.DIAMOND_PICKAXE);
BlockDamageEvent blockDamageEvent = new BlockDamageEvent(p, block, item, false);
PlayerInteractEvent blockDamageEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, item, block,
BlockFace.UP);
bp.onBlockDamage(blockDamageEvent);
verify(addon).inWorld(world);
verify(im).getIslandAt(location);
verify(world, times(80)).spawnParticle(eq(Particle.REDSTONE), eq(null), eq(5),
verify(world, times(48)).spawnParticle(eq(Particle.REDSTONE), eq(null), eq(5),
eq(0.1D), eq(0D), eq(0.1D), eq(1D), any(Particle.DustOptions.class));
}

Expand All @@ -131,9 +135,10 @@ public void testOnBlockDamage() {
*/
@Test
public void testOnBlockDamageWrongWorld() {
when(block.getWorld()).thenReturn(mock(World.class));
when(p.getWorld()).thenReturn(mock(World.class));
ItemStack item = new ItemStack(Material.DIAMOND_PICKAXE);
BlockDamageEvent blockDamageEvent = new BlockDamageEvent(p, block, item, false);
PlayerInteractEvent blockDamageEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, item, block,
BlockFace.UP);
bp.onBlockDamage(blockDamageEvent);
verify(im, never()).getIslandAt(location);
verify(world, never()).spawnParticle(any(Particle.class), any(Location.class),anyInt(),
Expand All @@ -147,7 +152,8 @@ public void testOnBlockDamageWrongWorld() {
public void testOnBlockDamageNotCenterMagicBlock() {
when(block.getLocation()).thenReturn(mock(Location.class));
ItemStack item = new ItemStack(Material.DIAMOND_PICKAXE);
BlockDamageEvent blockDamageEvent = new BlockDamageEvent(p, block, item, false);
PlayerInteractEvent blockDamageEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, item, block,
BlockFace.UP);
bp.onBlockDamage(blockDamageEvent);
verify(addon).inWorld(world);
verify(im).getIslandAt(any(Location.class));
Expand Down

0 comments on commit 377474f

Please sign in to comment.