Fix tests
This commit is contained in:
parent
361a61da5d
commit
255bd9abaa
|
@ -6,6 +6,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -33,6 +34,7 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
@ -51,6 +53,7 @@ import org.bukkit.entity.Zombie;
|
|||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -76,7 +79,6 @@ import world.bentobox.bentobox.api.configuration.WorldSettings;
|
|||
import world.bentobox.bentobox.api.events.island.IslandDeleteEvent;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.Database;
|
||||
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.island.IslandCache;
|
||||
|
@ -140,6 +142,7 @@ public class IslandsManagerTest {
|
|||
|
||||
// Class under test
|
||||
IslandsManager im;
|
||||
private Settings s;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -163,9 +166,9 @@ public class IslandsManagerTest {
|
|||
when(plugin.getIslandChunkDeletionManager()).thenReturn(chunkDeletionManager);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
s = new Settings();
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
when(s.getDatabaseType()).thenReturn(DatabaseType.JSON);
|
||||
//when(s.getDatabaseType()).thenReturn(DatabaseType.JSON);
|
||||
|
||||
// World
|
||||
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
|
@ -181,6 +184,7 @@ public class IslandsManagerTest {
|
|||
User.setPlugin(plugin);
|
||||
// Set up user already
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
when(player.getLocation()).thenReturn(location);
|
||||
User.getInstance(player);
|
||||
|
||||
// Locales
|
||||
|
@ -210,6 +214,8 @@ public class IslandsManagerTest {
|
|||
when(location.clone()).thenReturn(location);
|
||||
Chunk chunk = mock(Chunk.class);
|
||||
when(location.getChunk()).thenReturn(chunk);
|
||||
// Vector
|
||||
when(location.toVector()).thenReturn(new Vector(100D, 120D, 100D));
|
||||
when(space1.getRelative(BlockFace.DOWN)).thenReturn(ground);
|
||||
when(space1.getRelative(BlockFace.UP)).thenReturn(space2);
|
||||
// A safe spot
|
||||
|
@ -276,7 +282,6 @@ public class IslandsManagerTest {
|
|||
|
||||
when(iwm.getRemoveMobsWhitelist(any())).thenReturn(whitelist);
|
||||
|
||||
|
||||
// Monsters and animals
|
||||
when(zombie.getLocation()).thenReturn(location);
|
||||
when(zombie.getType()).thenReturn(EntityType.ZOMBIE);
|
||||
|
@ -288,13 +293,17 @@ public class IslandsManagerTest {
|
|||
when(cow.getType()).thenReturn(EntityType.COW);
|
||||
when(wither.getType()).thenReturn(EntityType.WITHER);
|
||||
when(wither.getRemoveWhenFarAway()).thenReturn(true);
|
||||
when(wither.getLocation()).thenReturn(location);
|
||||
when(creeper.getType()).thenReturn(EntityType.CREEPER);
|
||||
when(creeper.getRemoveWhenFarAway()).thenReturn(true);
|
||||
when(creeper.getLocation()).thenReturn(location);
|
||||
when(pufferfish.getType()).thenReturn(EntityType.PUFFERFISH);
|
||||
when(pufferfish.getLocation()).thenReturn(location);
|
||||
// Named monster
|
||||
when(skelly.getType()).thenReturn(EntityType.SKELETON);
|
||||
when(skelly.getCustomName()).thenReturn("Skelly");
|
||||
when(skelly.getRemoveWhenFarAway()).thenReturn(true);
|
||||
when(skelly.getLocation()).thenReturn(location);
|
||||
|
||||
Collection<Entity> collection = new ArrayList<>();
|
||||
collection.add(player);
|
||||
|
@ -305,9 +314,7 @@ public class IslandsManagerTest {
|
|||
collection.add(creeper);
|
||||
collection.add(pufferfish);
|
||||
collection.add(skelly);
|
||||
when(world
|
||||
.getNearbyEntities(any(Location.class), Mockito.anyDouble(), Mockito.anyDouble(), Mockito.anyDouble()))
|
||||
.thenReturn(collection);
|
||||
when(world.getNearbyEntities(any(Location.class), anyDouble(), anyDouble(), anyDouble())).thenReturn(collection);
|
||||
|
||||
|
||||
|
||||
|
@ -1105,7 +1112,8 @@ public class IslandsManagerTest {
|
|||
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#clearArea(Location)}.
|
||||
*/
|
||||
@Test
|
||||
public void testClearArea() {
|
||||
public void testClearAreaRemove() {
|
||||
s.setTeleportRemoveMobs(true);
|
||||
im.clearArea(location);
|
||||
// Only the correct entities should be cleared
|
||||
verify(zombie).remove();
|
||||
|
@ -1117,6 +1125,34 @@ public class IslandsManagerTest {
|
|||
verify(pufferfish, never()).remove();
|
||||
verify(skelly, never()).remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#clearArea(Location)}.
|
||||
*/
|
||||
@Test
|
||||
public void testClearArea() {
|
||||
im.clearArea(location);
|
||||
// Only the correct entities should be cleared
|
||||
verify(zombie, never()).remove();
|
||||
verify(player, never()).remove();
|
||||
verify(cow, never()).remove();
|
||||
verify(slime, never()).remove();
|
||||
verify(wither, never()).remove();
|
||||
verify(creeper, never()).remove();
|
||||
verify(pufferfish, never()).remove();
|
||||
verify(skelly, never()).remove();
|
||||
|
||||
verify(zombie).setVelocity(any(Vector.class));
|
||||
verify(slime).setVelocity(any(Vector.class));
|
||||
verify(creeper).setVelocity(any(Vector.class));
|
||||
verify(player, never()).setVelocity(any(Vector.class));
|
||||
verify(cow, never()).setVelocity(any(Vector.class));
|
||||
verify(wither, never()).setVelocity(any(Vector.class));
|
||||
verify(pufferfish, never()).setVelocity(any(Vector.class));
|
||||
verify(skelly, never()).setVelocity(any(Vector.class));
|
||||
|
||||
verify(world).playSound(zombie, Sound.ENTITY_ILLUSIONER_HURT, 1F, 5F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIslandById(String)}.
|
||||
|
|
Loading…
Reference in New Issue