Skip to content

Commit

Permalink
Corrected tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 29, 2021
1 parent 63e6a5d commit 79d1c74
Showing 1 changed file with 5 additions and 112 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package world.bentobox.greenhouses.listeners;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -22,18 +21,13 @@
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BoundingBox;
import org.junit.After;
Expand Down Expand Up @@ -145,11 +139,9 @@ public void testOnPlayerInteractInNether() {
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, EquipmentSlot.HAND);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item);
ghe.onPlayerInteractInNether(e);
assertEquals(Result.DENY, e.useItemInHand());
verify(nextBlock).setType(Material.WATER);
verify(item).setType(Material.BUCKET);
}

/**
Expand All @@ -164,11 +156,9 @@ public void testOnPlayerInteractInNetherNotInNether() {
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, EquipmentSlot.HAND);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item);
ghe.onPlayerInteractInNether(e);
assertEquals(Result.DEFAULT, e.useItemInHand());
verify(nextBlock, never()).setType(Material.WATER);
verify(item, never()).setType(Material.BUCKET);
}

/**
Expand All @@ -182,11 +172,9 @@ public void testOnPlayerInteractInNetherNotWaterBucket() {
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.ACACIA_BOAT);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, EquipmentSlot.HAND);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER, item);
ghe.onPlayerInteractInNether(e);
assertEquals(Result.DEFAULT, e.useItemInHand());
verify(nextBlock, never()).setType(Material.WATER);
verify(item, never()).setType(Material.BUCKET);
}

/**
Expand All @@ -201,47 +189,9 @@ public void testOnPlayerInteractInNetherNotInGreenhouse() {
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, EquipmentSlot.HAND);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item);
ghe.onPlayerInteractInNether(e);
assertEquals(Result.DEFAULT, e.useItemInHand());
verify(nextBlock, never()).setType(Material.WATER);
verify(item, never()).setType(Material.BUCKET);
}

/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerInteractInNether(org.bukkit.event.player.PlayerInteractEvent)}.
*/
@Test
public void testOnPlayerInteractInNetherNullItem() {
Block clickedBlock = mock(Block.class);
when(clickedBlock.getLocation()).thenReturn(location);
Block nextBlock = mock(Block.class);
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, null, clickedBlock, BlockFace.EAST, EquipmentSlot.HAND);
ghe.onPlayerInteractInNether(e);
assertEquals(Result.DEFAULT, e.useItemInHand());
verify(nextBlock, never()).setType(Material.WATER);
verify(item, never()).setType(Material.BUCKET);
}

/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerInteractInNether(org.bukkit.event.player.PlayerInteractEvent)}.
*/
@Test
public void testOnPlayerInteractInNetherNotBlockClick() {
Block clickedBlock = mock(Block.class);
when(clickedBlock.getLocation()).thenReturn(location);
Block nextBlock = mock(Block.class);
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_AIR, item, clickedBlock, BlockFace.EAST, EquipmentSlot.HAND);
ghe.onPlayerInteractInNether(e);
assertEquals(Result.DEFAULT, e.useItemInHand());
verify(nextBlock, never()).setType(Material.WATER);
verify(item, never()).setType(Material.BUCKET);
}

/**
Expand Down Expand Up @@ -400,63 +350,6 @@ public void testOnBlockBreak() {
verify(gm).removeGreenhouse(any());
}

/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
*/
@Test
public void testOnPlayerBlockPlace() {
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getY()).thenReturn(255);
when(block.getWorld()).thenReturn(world);
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
BlockState bs = mock(BlockState.class);
Block pa = mock(Block.class);
ItemStack item = mock(ItemStack.class);
BlockPlaceEvent e = new BlockPlaceEvent(block, bs, pa, item, player, true, EquipmentSlot.HAND);
ghe.onPlayerBlockPlace(e);
assertTrue(e.isCancelled());
verify(user).sendMessage(eq("greenhouses.error.cannot-place"));
}

/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
*/
@Test
public void testOnPlayerBlockPlaceNether() {
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getY()).thenReturn(255);
when(block.getWorld()).thenReturn(world);
when(world.getEnvironment()).thenReturn(Environment.NETHER);
BlockState bs = mock(BlockState.class);
Block pa = mock(Block.class);
ItemStack item = mock(ItemStack.class);
BlockPlaceEvent e = new BlockPlaceEvent(block, bs, pa, item, player, true, EquipmentSlot.HAND);
ghe.onPlayerBlockPlace(e);
assertFalse(e.isCancelled());
verify(user, never()).sendMessage(eq("greenhouses.error.cannot-place"));
}

/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
*/
@Test
public void testOnPlayerBlockPlaceBelowGH() {
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getY()).thenReturn(0);
when(block.getWorld()).thenReturn(world);
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
BlockState bs = mock(BlockState.class);
Block pa = mock(Block.class);
ItemStack item = mock(ItemStack.class);
BlockPlaceEvent e = new BlockPlaceEvent(block, bs, pa, item, player, true, EquipmentSlot.HAND);
ghe.onPlayerBlockPlace(e);
assertFalse(e.isCancelled());
verify(user, never()).sendMessage(eq("greenhouses.error.cannot-place"));
}

/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPistonPush(org.bukkit.event.block.BlockPistonExtendEvent)}.
*/
Expand Down

0 comments on commit 79d1c74

Please sign in to comment.