use of net.glowstone.net.message.play.player.UseItemMessage in project Glowstone by GlowstoneMC.
the class UseItemHandlerTest method testRightClickAir.
@Test
public void testRightClickAir() {
// prepare objects under test
Location location = new Location(world, 1.0, 1.0, 1.0);
Location playerLocation = new Location(world, 2.0, 2.0, 2.0);
GlowPlayerInventory inventory = new GlowPlayerInventory(player);
ItemStack stack = new ItemStack(Material.JUNGLE_BOAT);
GlowBoat boat = new GlowBoat(location);
inventory.setItemInMainHand(stack);
UseItemMessage message = new UseItemMessage(EquipmentSlot.HAND.ordinal());
PlayerInteractEvent event = new PlayerInteractEvent(player, Action.RIGHT_CLICK_AIR, stack, null, null);
// prepare mock behaviours
Mockito.when(session.getPlayer()).thenReturn(player);
Mockito.when(player.getInventory()).thenReturn(inventory);
Mockito.when(player.getLocation()).thenReturn(playerLocation);
Mockito.when(player.getTargetBlock((Set<Material>) null, 5)).thenReturn(targetBlock);
Mockito.when(player.getGameMode()).thenReturn(GameMode.SURVIVAL);
Mockito.when(eventFactory.onPlayerInteract(player, Action.RIGHT_CLICK_AIR, EquipmentSlot.HAND)).thenReturn(event);
Mockito.when(emptyBlock.isEmpty()).thenReturn(Boolean.TRUE);
Mockito.when(emptyBlock.getLocation()).thenReturn(location);
Mockito.when(targetBlock.isEmpty()).thenReturn(Boolean.FALSE);
Mockito.when(targetBlock.getRelative(BlockFace.UP)).thenReturn(emptyBlock);
Mockito.when(targetBlock.getWorld()).thenReturn(world);
Mockito.when(world.spawn(location, Boat.class)).thenReturn(boat);
// run test
Assert.assertTrue(inventory.contains(Material.JUNGLE_BOAT, 1));
UseItemHandler handler = new UseItemHandler();
handler.handle(session, message);
// after calling use item and creating a boat, the inventory no longer contains a boat
Assert.assertFalse(inventory.contains(Material.JUNGLE_BOAT, 1));
}
Aggregations