mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-20 06:11:37 +01:00
Fixed and added tests for new deathCount option
Fixes test failures from commit a6d25d68a9
I added some more tests to check for in world as well as death count
being on/off.
This commit is contained in:
parent
14b7a3aa82
commit
84a79fe1de
@ -13,6 +13,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@ -21,6 +22,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
|||||||
import org.powermock.reflect.Whitebox;
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
@ -29,19 +31,21 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
|
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
|
||||||
public class DeathListenerTest {
|
public class DeathListenerTest {
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
private BentoBox plugin;
|
||||||
|
private PlayersManager pm;
|
||||||
|
private WorldSettings worldSettings;
|
||||||
|
private World world;
|
||||||
|
private UUID uuid;
|
||||||
|
private IslandWorldManager iwm;
|
||||||
|
|
||||||
@Test
|
@Before
|
||||||
public void testDeathListener() {
|
public void setUp() {
|
||||||
assertNotNull(new DeathListener(mock(BentoBox.class)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnPlayerDeathEvent() {
|
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
// Island World Manager
|
// Island World Manager
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||||
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
||||||
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
|
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
|
||||||
@ -49,16 +53,32 @@ public class DeathListenerTest {
|
|||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
Player player = mock(Player.class);
|
player = mock(Player.class);
|
||||||
World world = mock(World.class);
|
world = mock(World.class);
|
||||||
when(player.getWorld()).thenReturn(world);
|
when(player.getWorld()).thenReturn(world);
|
||||||
when(player.getLocation()).thenReturn(mock(Location.class));
|
when(player.getLocation()).thenReturn(mock(Location.class));
|
||||||
UUID uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
|
||||||
PlayersManager pm = mock(PlayersManager.class);
|
pm = mock(PlayersManager.class);
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
|
worldSettings = mock(WorldSettings.class);
|
||||||
|
when(worldSettings.isDeathsCounted()).thenReturn(true);
|
||||||
|
// Deaths counted
|
||||||
|
when(iwm.getWorldSettings(Mockito.any())).thenReturn(worldSettings );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeathListener() {
|
||||||
|
assertNotNull(new DeathListener(mock(BentoBox.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnPlayerDeathEventDeathsCounted() {
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
DeathListener dl = new DeathListener(plugin);
|
DeathListener dl = new DeathListener(plugin);
|
||||||
|
|
||||||
@ -67,4 +87,27 @@ public class DeathListenerTest {
|
|||||||
Mockito.verify(pm).addDeath(world, uuid);
|
Mockito.verify(pm).addDeath(world, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnPlayerDeathEventDeathsNotCounted() {
|
||||||
|
when(worldSettings.isDeathsCounted()).thenReturn(false);
|
||||||
|
// Test
|
||||||
|
DeathListener dl = new DeathListener(plugin);
|
||||||
|
|
||||||
|
PlayerDeathEvent e = new PlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
|
||||||
|
dl.onPlayerDeathEvent(e);
|
||||||
|
Mockito.verify(pm, Mockito.never()).addDeath(world, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnPlayerDeathEventDeathsCountedNotInWorld() {
|
||||||
|
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
||||||
|
// Test
|
||||||
|
DeathListener dl = new DeathListener(plugin);
|
||||||
|
|
||||||
|
PlayerDeathEvent e = new PlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
|
||||||
|
dl.onPlayerDeathEvent(e);
|
||||||
|
Mockito.verify(pm, Mockito.never()).addDeath(world, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user