2018-07-31 18:03:32 +02:00
|
|
|
package world.bentobox.bentobox.managers;
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2019-06-01 22:22:28 +02:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
2019-08-05 06:44:46 +02:00
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
import static org.mockito.ArgumentMatchers.anyString;
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
2019-06-01 22:22:28 +02:00
|
|
|
import static org.mockito.Mockito.mock;
|
2019-07-19 06:58:16 +02:00
|
|
|
import static org.mockito.Mockito.never;
|
2019-08-05 06:44:46 +02:00
|
|
|
import static org.mockito.Mockito.verify;
|
2019-06-01 22:22:28 +02:00
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
2019-07-06 05:11:06 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
2019-06-01 22:22:28 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
2019-07-06 05:11:06 +02:00
|
|
|
import java.util.Comparator;
|
2019-06-01 22:22:28 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2018-03-12 01:21:15 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2019-05-27 02:35:19 +02:00
|
|
|
import org.bukkit.Chunk;
|
2018-05-06 07:26:25 +02:00
|
|
|
import org.bukkit.GameMode;
|
2018-03-12 01:21:15 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
import org.bukkit.block.BlockState;
|
2018-08-03 04:01:23 +02:00
|
|
|
import org.bukkit.block.data.BlockData;
|
2018-06-25 02:57:31 +02:00
|
|
|
import org.bukkit.entity.Cow;
|
|
|
|
import org.bukkit.entity.Creeper;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
2018-05-06 07:26:25 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2019-03-10 01:54:54 +01:00
|
|
|
import org.bukkit.entity.PufferFish;
|
2019-07-19 06:58:16 +02:00
|
|
|
import org.bukkit.entity.Skeleton;
|
2018-06-25 02:57:31 +02:00
|
|
|
import org.bukkit.entity.Slime;
|
|
|
|
import org.bukkit.entity.Wither;
|
|
|
|
import org.bukkit.entity.Zombie;
|
2019-01-13 02:12:30 +01:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
2018-05-06 07:26:25 +02:00
|
|
|
import org.bukkit.scheduler.BukkitScheduler;
|
2019-07-06 05:11:06 +02:00
|
|
|
import org.junit.After;
|
2018-05-06 07:26:25 +02:00
|
|
|
import org.junit.Before;
|
2018-03-12 01:21:15 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
2020-02-04 21:20:31 +01:00
|
|
|
import org.mockito.ArgumentCaptor;
|
2019-05-24 05:09:35 +02:00
|
|
|
import org.mockito.Mock;
|
2018-05-06 07:26:25 +02:00
|
|
|
import org.mockito.Mockito;
|
|
|
|
import org.mockito.stubbing.Answer;
|
|
|
|
import org.powermock.api.mockito.PowerMockito;
|
2018-03-12 01:21:15 +01:00
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
|
|
import org.powermock.modules.junit4.PowerMockRunner;
|
|
|
|
import org.powermock.reflect.Whitebox;
|
2019-06-01 22:22:28 +02:00
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
import com.google.common.collect.ImmutableSet.Builder;
|
|
|
|
|
2019-11-14 00:10:33 +01:00
|
|
|
import io.papermc.lib.PaperLib;
|
|
|
|
import io.papermc.lib.environments.CraftBukkitEnvironment;
|
|
|
|
import io.papermc.lib.environments.Environment;
|
2018-07-31 18:03:32 +02:00
|
|
|
import world.bentobox.bentobox.BentoBox;
|
|
|
|
import world.bentobox.bentobox.Settings;
|
|
|
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
2020-12-27 19:35:49 +01:00
|
|
|
import world.bentobox.bentobox.api.events.island.IslandDeleteEvent;
|
2018-07-31 18:03:32 +02:00
|
|
|
import world.bentobox.bentobox.api.user.User;
|
2019-07-06 05:11:06 +02:00
|
|
|
import world.bentobox.bentobox.database.Database;
|
2019-05-08 21:15:22 +02:00
|
|
|
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
|
2018-07-31 18:03:32 +02:00
|
|
|
import world.bentobox.bentobox.database.objects.Island;
|
|
|
|
import world.bentobox.bentobox.lists.Flags;
|
|
|
|
import world.bentobox.bentobox.managers.island.IslandCache;
|
|
|
|
import world.bentobox.bentobox.util.Util;
|
2018-03-12 01:21:15 +01:00
|
|
|
|
|
|
|
@RunWith(PowerMockRunner.class)
|
2018-08-04 18:37:21 +02:00
|
|
|
@PrepareForTest( { Bukkit.class, BentoBox.class, Util.class, Location.class })
|
2018-03-12 01:21:15 +01:00
|
|
|
public class IslandsManagerTest {
|
|
|
|
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-12-16 08:38:20 +01:00
|
|
|
private BentoBox plugin;
|
2018-05-06 07:26:25 +02:00
|
|
|
private UUID uuid;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-05-06 07:26:25 +02:00
|
|
|
private User user;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-05-06 07:26:25 +02:00
|
|
|
private PlayersManager pm;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-05-06 07:26:25 +02:00
|
|
|
private Player player;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
|
|
|
private World world;
|
2018-05-06 07:26:25 +02:00
|
|
|
private IslandsManager manager;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-05-06 07:26:25 +02:00
|
|
|
private Block space1;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-05-06 07:26:25 +02:00
|
|
|
private Block ground;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-05-06 07:26:25 +02:00
|
|
|
private Block space2;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-05-06 07:26:25 +02:00
|
|
|
private Location location;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-05-21 01:09:57 +02:00
|
|
|
private IslandWorldManager iwm;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-08-04 18:37:21 +02:00
|
|
|
private IslandCache islandCache;
|
|
|
|
private Optional<Island> optionalIsland;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2018-09-03 05:45:31 +02:00
|
|
|
private Island is;
|
2019-05-24 05:09:35 +02:00
|
|
|
@Mock
|
2019-01-13 02:12:30 +01:00
|
|
|
private PluginManager pim;
|
2019-07-06 05:11:06 +02:00
|
|
|
// Database
|
|
|
|
Database<Island> db;
|
2019-07-19 06:58:16 +02:00
|
|
|
@Mock
|
|
|
|
private Zombie zombie;
|
|
|
|
@Mock
|
|
|
|
private Slime slime;
|
|
|
|
@Mock
|
|
|
|
private Cow cow;
|
|
|
|
@Mock
|
|
|
|
private Wither wither;
|
|
|
|
@Mock
|
|
|
|
private Creeper creeper;
|
|
|
|
@Mock
|
|
|
|
private PufferFish pufferfish;
|
|
|
|
@Mock
|
|
|
|
private Skeleton skelly;
|
2018-05-06 07:26:25 +02:00
|
|
|
|
2019-08-29 21:18:45 +02:00
|
|
|
private Material sign;
|
|
|
|
private Material wallSign;
|
|
|
|
|
2019-11-14 00:10:33 +01:00
|
|
|
private Environment env;
|
|
|
|
|
2019-08-29 21:18:45 +02:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
/**
|
|
|
|
* @throws java.lang.Exception
|
|
|
|
*/
|
2019-07-06 05:11:06 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2018-05-06 07:26:25 +02:00
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
2019-07-06 05:11:06 +02:00
|
|
|
// Clear any lingering database
|
2019-12-06 17:29:29 +01:00
|
|
|
tearDown();
|
2018-05-06 07:26:25 +02:00
|
|
|
// Set up plugin
|
2019-07-06 05:11:06 +02:00
|
|
|
plugin = mock(BentoBox.class);
|
2018-07-29 22:21:46 +02:00
|
|
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2019-07-06 05:11:06 +02:00
|
|
|
// island world mgr
|
|
|
|
when(world.getName()).thenReturn("world");
|
|
|
|
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
|
|
|
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
|
|
|
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
|
|
|
when(plugin.getIWM()).thenReturn(iwm);
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
// Settings
|
2018-08-05 06:50:10 +02:00
|
|
|
Settings s = mock(Settings.class);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(plugin.getSettings()).thenReturn(s);
|
2019-05-08 21:15:22 +02:00
|
|
|
when(s.getDatabaseType()).thenReturn(DatabaseType.JSON);
|
2018-05-06 07:26:25 +02:00
|
|
|
|
2019-07-06 05:11:06 +02:00
|
|
|
// World
|
|
|
|
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
|
|
|
|
|
|
|
// Command manager
|
|
|
|
CommandsManager cm = mock(CommandsManager.class);
|
|
|
|
when(plugin.getCommandsManager()).thenReturn(cm);
|
2018-05-06 07:26:25 +02:00
|
|
|
// Player
|
|
|
|
when(user.isOp()).thenReturn(false);
|
|
|
|
uuid = UUID.randomUUID();
|
|
|
|
when(user.getUniqueId()).thenReturn(uuid);
|
|
|
|
when(user.getPlayer()).thenReturn(player);
|
|
|
|
User.setPlugin(plugin);
|
|
|
|
// Set up user already
|
|
|
|
User.getInstance(player);
|
|
|
|
|
2018-06-25 01:22:44 +02:00
|
|
|
// Locales
|
2018-05-06 07:26:25 +02:00
|
|
|
LocalesManager lm = mock(LocalesManager.class);
|
|
|
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
|
|
|
when(lm.get(any(), any())).thenReturn("mock translation");
|
|
|
|
|
2019-05-11 16:11:57 +02:00
|
|
|
// Placeholders
|
|
|
|
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
|
|
|
|
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
|
|
|
when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation");
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
// Has team
|
|
|
|
when(plugin.getPlayers()).thenReturn(pm);
|
|
|
|
|
2019-01-13 02:12:30 +01:00
|
|
|
// Scheduler
|
2018-05-06 07:26:25 +02:00
|
|
|
BukkitScheduler sch = mock(BukkitScheduler.class);
|
|
|
|
PowerMockito.mockStatic(Bukkit.class);
|
|
|
|
when(Bukkit.getScheduler()).thenReturn(sch);
|
2019-11-14 00:10:33 +01:00
|
|
|
// version
|
|
|
|
when(Bukkit.getVersion()).thenReturn("Paper version git-Paper-225 (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)");
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
// Standard location
|
|
|
|
manager = new IslandsManager(plugin);
|
2018-05-18 06:25:12 +02:00
|
|
|
when(location.getWorld()).thenReturn(world);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(location.getBlock()).thenReturn(space1);
|
2018-12-09 04:24:31 +01:00
|
|
|
when(location.getWorld()).thenReturn(world);
|
2020-04-23 03:25:10 +02:00
|
|
|
when(location.clone()).thenReturn(location);
|
2019-05-27 02:35:19 +02:00
|
|
|
Chunk chunk = mock(Chunk.class);
|
|
|
|
when(location.getChunk()).thenReturn(chunk);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(space1.getRelative(BlockFace.DOWN)).thenReturn(ground);
|
|
|
|
when(space1.getRelative(BlockFace.UP)).thenReturn(space2);
|
|
|
|
// A safe spot
|
|
|
|
when(ground.getType()).thenReturn(Material.STONE);
|
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
|
|
|
// Neutral BlockState
|
2018-08-05 06:50:10 +02:00
|
|
|
BlockState blockState = mock(BlockState.class);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(ground.getState()).thenReturn(blockState);
|
2018-08-03 04:01:23 +02:00
|
|
|
BlockData bd = mock(BlockData.class);
|
|
|
|
when(blockState.getBlockData()).thenReturn(bd);
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
// Online players
|
|
|
|
// Return a set of online players
|
2018-08-05 06:50:10 +02:00
|
|
|
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> new HashSet<>());
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-05-19 08:08:18 +02:00
|
|
|
// Worlds
|
2018-05-25 21:19:46 +02:00
|
|
|
when(plugin.getIWM()).thenReturn(iwm);
|
2019-05-24 05:09:35 +02:00
|
|
|
// Default is player is in the world
|
2018-09-29 18:01:20 +02:00
|
|
|
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
|
|
|
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2019-05-24 05:09:35 +02:00
|
|
|
// Worlds translate to world
|
2018-05-25 21:19:46 +02:00
|
|
|
PowerMockito.mockStatic(Util.class);
|
2019-08-05 06:44:46 +02:00
|
|
|
when(Util.getWorld(any())).thenReturn(world);
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-08-04 18:37:21 +02:00
|
|
|
// Mock island cache
|
2019-08-05 06:44:46 +02:00
|
|
|
when(islandCache.getIslandAt(any(Location.class))).thenReturn(is);
|
2018-08-04 18:37:21 +02:00
|
|
|
optionalIsland = Optional.ofNullable(is);
|
|
|
|
|
2018-09-26 05:45:43 +02:00
|
|
|
// User location
|
|
|
|
when(user.getLocation()).thenReturn(location);
|
2018-08-04 18:37:21 +02:00
|
|
|
|
2019-10-19 02:32:54 +02:00
|
|
|
// Plugin Manager for events
|
|
|
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
2019-01-16 00:23:17 +01:00
|
|
|
|
|
|
|
// Addon
|
2019-08-05 06:44:46 +02:00
|
|
|
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
2019-01-16 00:23:17 +01:00
|
|
|
|
2019-03-10 01:54:54 +01:00
|
|
|
// Cover hostile entities
|
2019-08-05 06:44:46 +02:00
|
|
|
when(Util.isHostileEntity(any())).thenCallRealMethod();
|
2019-03-10 01:54:54 +01:00
|
|
|
|
2019-07-19 06:58:16 +02:00
|
|
|
// Set up island entities
|
|
|
|
WorldSettings ws = mock(WorldSettings.class);
|
|
|
|
when(iwm.getWorldSettings(eq(world))).thenReturn(ws);
|
|
|
|
Map<String, Boolean> worldFlags = new HashMap<>();
|
|
|
|
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
|
|
|
|
|
|
|
Flags.REMOVE_MOBS.setSetting(world, true);
|
|
|
|
// Default whitelist
|
|
|
|
Set<EntityType> whitelist = new HashSet<>();
|
|
|
|
whitelist.add(EntityType.ENDERMAN);
|
|
|
|
whitelist.add(EntityType.WITHER);
|
|
|
|
whitelist.add(EntityType.ZOMBIE_VILLAGER);
|
2020-06-26 22:09:33 +02:00
|
|
|
|
2019-08-05 06:44:46 +02:00
|
|
|
when(iwm.getRemoveMobsWhitelist(any())).thenReturn(whitelist);
|
2019-07-19 06:58:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Monsters and animals
|
|
|
|
when(zombie.getLocation()).thenReturn(location);
|
|
|
|
when(zombie.getType()).thenReturn(EntityType.ZOMBIE);
|
|
|
|
when(slime.getLocation()).thenReturn(location);
|
|
|
|
when(slime.getType()).thenReturn(EntityType.SLIME);
|
|
|
|
when(cow.getLocation()).thenReturn(location);
|
|
|
|
when(cow.getType()).thenReturn(EntityType.COW);
|
|
|
|
when(wither.getType()).thenReturn(EntityType.WITHER);
|
|
|
|
when(creeper.getType()).thenReturn(EntityType.CREEPER);
|
|
|
|
when(pufferfish.getType()).thenReturn(EntityType.PUFFERFISH);
|
|
|
|
// Named monster
|
|
|
|
when(skelly.getType()).thenReturn(EntityType.SKELETON);
|
|
|
|
when(skelly.getCustomName()).thenReturn("Skelly");
|
|
|
|
|
|
|
|
Collection<Entity> collection = new ArrayList<>();
|
|
|
|
collection.add(player);
|
|
|
|
collection.add(zombie);
|
|
|
|
collection.add(cow);
|
|
|
|
collection.add(slime);
|
|
|
|
collection.add(wither);
|
|
|
|
collection.add(creeper);
|
|
|
|
collection.add(pufferfish);
|
|
|
|
collection.add(skelly);
|
|
|
|
when(world
|
2019-08-05 06:44:46 +02:00
|
|
|
.getNearbyEntities(any(Location.class), Mockito.anyDouble(), Mockito.anyDouble(), Mockito.anyDouble()))
|
2019-07-19 06:58:16 +02:00
|
|
|
.thenReturn(collection);
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-06 05:11:06 +02:00
|
|
|
// database must be mocked here
|
|
|
|
db = mock(Database.class);
|
2019-08-29 21:18:45 +02:00
|
|
|
|
|
|
|
// Signs
|
|
|
|
sign = Material.getMaterial("SIGN");
|
|
|
|
if (sign == null) {
|
|
|
|
sign = Material.getMaterial("OAK_SIGN");
|
|
|
|
}
|
|
|
|
wallSign = Material.getMaterial("WALL_SIGN");
|
|
|
|
if (wallSign == null) {
|
|
|
|
wallSign = Material.getMaterial("OAK_WALL_SIGN");
|
|
|
|
}
|
2019-11-14 00:10:33 +01:00
|
|
|
|
|
|
|
// PaperLib
|
|
|
|
env = new CraftBukkitEnvironment();
|
|
|
|
PaperLib.setCustomEnvironment(env);
|
2019-12-01 01:17:38 +01:00
|
|
|
|
|
|
|
// Util strip spaces
|
|
|
|
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
|
2018-03-12 01:21:15 +01:00
|
|
|
}
|
|
|
|
|
2019-07-06 05:11:06 +02:00
|
|
|
@After
|
2019-12-06 17:29:29 +01:00
|
|
|
public void tearDown() throws IOException{
|
2019-07-06 05:11:06 +02:00
|
|
|
//remove any database data
|
|
|
|
File file = new File("database");
|
|
|
|
Path pathToBeDeleted = file.toPath();
|
|
|
|
if (file.exists()) {
|
|
|
|
Files.walk(pathToBeDeleted)
|
|
|
|
.sorted(Comparator.reverseOrder())
|
|
|
|
.map(Path::toFile)
|
|
|
|
.forEach(File::delete);
|
|
|
|
}
|
2019-12-06 17:29:29 +01:00
|
|
|
Mockito.framework().clearInlineMocks();
|
2019-07-06 05:11:06 +02:00
|
|
|
}
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testIsSafeLocationSafe() {
|
|
|
|
IslandsManager manager = new IslandsManager(plugin);
|
|
|
|
assertTrue(manager.isSafeLocation(location));
|
|
|
|
}
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2018-12-09 04:24:31 +01:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testIsSafeLocationNullWorld() {
|
|
|
|
when(location.getWorld()).thenReturn(null);
|
|
|
|
IslandsManager manager = new IslandsManager(plugin);
|
|
|
|
assertFalse(manager.isSafeLocation(location));
|
|
|
|
}
|
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testIsSafeLocationNonSolidGround() {
|
2018-06-25 01:22:44 +02:00
|
|
|
when(ground.getType()).thenReturn(Material.WATER);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertFalse(manager.isSafeLocation(location));
|
|
|
|
}
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testIsSafeLocationSubmerged() {
|
|
|
|
when(ground.getType()).thenReturn(Material.STONE);
|
2020-04-23 03:25:10 +02:00
|
|
|
when(space1.getType()).thenReturn(Material.WATER);
|
|
|
|
when(space2.getType()).thenReturn(Material.WATER);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertFalse(manager.isSafeLocation(location));
|
|
|
|
}
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2020-09-07 01:16:06 +02:00
|
|
|
@Test
|
|
|
|
public void testCheckIfSafeTrapdoor() {
|
|
|
|
for (Material d : Material.values()) {
|
|
|
|
if (d.name().contains("DOOR")) {
|
|
|
|
for (Material s : Material.values()) {
|
|
|
|
if (s.name().contains("_SIGN")) {
|
|
|
|
assertFalse("Fail " + d.name() + " " + s.name(), manager.checkIfSafe(world, d, s, Material.AIR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
2018-06-25 01:22:44 +02:00
|
|
|
public void testIsSafeLocationPortals() {
|
2018-05-06 07:26:25 +02:00
|
|
|
when(ground.getType()).thenReturn(Material.STONE);
|
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
2018-08-01 11:21:29 +02:00
|
|
|
when(space2.getType()).thenReturn(Material.NETHER_PORTAL);
|
2020-04-23 03:25:10 +02:00
|
|
|
assertTrue(manager.isSafeLocation(location));
|
2018-05-06 07:26:25 +02:00
|
|
|
when(ground.getType()).thenReturn(Material.STONE);
|
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
2018-08-01 11:21:29 +02:00
|
|
|
when(space2.getType()).thenReturn(Material.END_PORTAL);
|
2020-04-23 03:25:10 +02:00
|
|
|
assertTrue(manager.isSafeLocation(location));
|
2018-05-06 07:26:25 +02:00
|
|
|
when(ground.getType()).thenReturn(Material.STONE);
|
2018-08-01 11:21:29 +02:00
|
|
|
when(space1.getType()).thenReturn(Material.NETHER_PORTAL);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
2020-04-23 03:25:10 +02:00
|
|
|
assertTrue(manager.isSafeLocation(location));
|
2018-05-06 07:26:25 +02:00
|
|
|
when(ground.getType()).thenReturn(Material.STONE);
|
2018-08-01 11:21:29 +02:00
|
|
|
when(space1.getType()).thenReturn(Material.END_PORTAL);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
2020-04-23 03:25:10 +02:00
|
|
|
assertTrue(manager.isSafeLocation(location));
|
2018-08-01 11:21:29 +02:00
|
|
|
when(ground.getType()).thenReturn(Material.NETHER_PORTAL);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
|
|
|
assertFalse(manager.isSafeLocation(location));
|
2018-08-01 11:21:29 +02:00
|
|
|
when(ground.getType()).thenReturn(Material.END_PORTAL);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
|
|
|
assertFalse(manager.isSafeLocation(location));
|
|
|
|
}
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testIsSafeLocationLava() {
|
|
|
|
when(ground.getType()).thenReturn(Material.LAVA);
|
2018-03-12 01:21:15 +01:00
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertFalse("In lava", manager.isSafeLocation(location));
|
|
|
|
when(ground.getType()).thenReturn(Material.AIR);
|
|
|
|
when(space1.getType()).thenReturn(Material.LAVA);
|
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
|
|
|
assertFalse("In lava", manager.isSafeLocation(location));
|
|
|
|
when(ground.getType()).thenReturn(Material.AIR);
|
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
|
|
|
when(space2.getType()).thenReturn(Material.LAVA);
|
|
|
|
assertFalse("In lava", manager.isSafeLocation(location));
|
2018-06-25 01:22:44 +02:00
|
|
|
}
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testTrapDoor() {
|
2018-08-01 11:21:29 +02:00
|
|
|
when(ground.getType()).thenReturn(Material.OAK_TRAPDOOR);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertFalse("Open trapdoor", manager.isSafeLocation(location));
|
|
|
|
when(ground.getType()).thenReturn(Material.IRON_TRAPDOOR);
|
|
|
|
assertFalse("Open iron trapdoor", manager.isSafeLocation(location));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testBadBlocks() {
|
|
|
|
// Fences
|
2018-05-27 17:50:14 +02:00
|
|
|
Arrays.stream(Material.values()).filter(m -> m.toString().contains("FENCE")).forEach(m -> {
|
2018-03-12 01:21:15 +01:00
|
|
|
when(ground.getType()).thenReturn(m);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertFalse("Fence :" + m.toString(), manager.isSafeLocation(location));
|
|
|
|
});
|
|
|
|
// Signs
|
2019-08-29 21:18:45 +02:00
|
|
|
when(ground.getType()).thenReturn(sign);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertFalse("Sign", manager.isSafeLocation(location));
|
2019-08-29 21:18:45 +02:00
|
|
|
when(ground.getType()).thenReturn(wallSign);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertFalse("Sign", manager.isSafeLocation(location));
|
|
|
|
// Bad Blocks
|
2018-08-01 11:21:29 +02:00
|
|
|
Material[] badMats = {Material.CACTUS, Material.OAK_BOAT};
|
2018-05-06 07:26:25 +02:00
|
|
|
Arrays.asList(badMats).forEach(m -> {
|
|
|
|
when(ground.getType()).thenReturn(m);
|
|
|
|
assertFalse("Bad mat :" + m.toString(), manager.isSafeLocation(location));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testSolidBlocks() {
|
|
|
|
when(space1.getType()).thenReturn(Material.STONE);
|
|
|
|
assertFalse("Solid", manager.isSafeLocation(location));
|
|
|
|
|
2018-03-12 01:21:15 +01:00
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(space2.getType()).thenReturn(Material.STONE);
|
|
|
|
assertFalse("Solid", manager.isSafeLocation(location));
|
2018-03-12 01:21:15 +01:00
|
|
|
|
2019-08-29 21:18:45 +02:00
|
|
|
when(space1.getType()).thenReturn(wallSign);
|
2018-03-12 01:21:15 +01:00
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertTrue("Wall sign 1", manager.isSafeLocation(location));
|
|
|
|
|
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
2019-08-29 21:18:45 +02:00
|
|
|
when(space2.getType()).thenReturn(wallSign);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertTrue("Wall sign 2", manager.isSafeLocation(location));
|
|
|
|
|
2019-08-29 21:18:45 +02:00
|
|
|
when(space1.getType()).thenReturn(sign);
|
2018-05-06 07:26:25 +02:00
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
|
|
|
assertTrue("Wall sign 1", manager.isSafeLocation(location));
|
|
|
|
|
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
2019-08-29 21:18:45 +02:00
|
|
|
when(space2.getType()).thenReturn(sign);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertTrue("Wall sign 2", manager.isSafeLocation(location));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#bigScan(org.bukkit.Location, int)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
2018-04-05 04:25:13 +02:00
|
|
|
@Test
|
2019-01-18 11:33:29 +01:00
|
|
|
public void testBigScan() {
|
2018-04-05 04:25:13 +02:00
|
|
|
IslandsManager manager = new IslandsManager(plugin);
|
2018-05-06 07:26:25 +02:00
|
|
|
|
2018-04-05 04:25:13 +02:00
|
|
|
Location location = mock(Location.class);
|
|
|
|
when(location.getWorld()).thenReturn(world);
|
|
|
|
when(location.getBlockX()).thenReturn(0);
|
|
|
|
when(location.getBlockY()).thenReturn(0);
|
|
|
|
when(location.getBlockZ()).thenReturn(0);
|
|
|
|
|
|
|
|
Block space1 = mock(Block.class);
|
|
|
|
Block ground = mock(Block.class);
|
|
|
|
Block space2 = mock(Block.class);
|
|
|
|
|
|
|
|
when(location.getBlock()).thenReturn(space1);
|
|
|
|
|
|
|
|
when(ground.getType()).thenReturn(Material.GRASS);
|
|
|
|
when(space1.getType()).thenReturn(Material.AIR);
|
|
|
|
when(space2.getType()).thenReturn(Material.AIR);
|
|
|
|
when(space1.getRelative(BlockFace.DOWN)).thenReturn(ground);
|
|
|
|
when(space1.getRelative(BlockFace.UP)).thenReturn(space2);
|
|
|
|
|
|
|
|
BlockState blockState = mock(BlockState.class);
|
|
|
|
when(ground.getState()).thenReturn(blockState);
|
2018-05-06 07:26:25 +02:00
|
|
|
|
2018-04-05 04:25:13 +02:00
|
|
|
// Negative value = full island scan
|
2020-09-07 01:16:06 +02:00
|
|
|
// No island here yet
|
2018-04-05 04:25:13 +02:00
|
|
|
assertNull(manager.bigScan(location, -1));
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#createIsland(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testCreateIslandLocation() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
Island island = im.createIsland(location);
|
|
|
|
assertNotNull(island);
|
2018-06-24 00:45:09 +02:00
|
|
|
assertEquals(island.getCenter().getWorld(), location.getWorld());
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#createIsland(org.bukkit.Location, java.util.UUID)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testCreateIslandLocationUUID() {
|
|
|
|
UUID owner = UUID.randomUUID();
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
Island island = im.createIsland(location, owner);
|
|
|
|
assertNotNull(island);
|
2018-06-24 00:45:09 +02:00
|
|
|
assertEquals(island.getCenter().getWorld(), location.getWorld());
|
2018-05-06 07:26:25 +02:00
|
|
|
assertEquals(owner, island.getOwner());
|
|
|
|
}
|
|
|
|
|
2019-01-13 02:12:30 +01:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#deleteIsland(world.bentobox.bentobox.database.objects.Island, boolean)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testDeleteIslandIslandBooleanNoBlockRemoval() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-05-06 07:26:25 +02:00
|
|
|
UUID owner = UUID.randomUUID();
|
|
|
|
Island island = im.createIsland(location, owner);
|
2019-06-27 04:03:56 +02:00
|
|
|
im.deleteIsland(island, false, owner);
|
2019-01-13 02:12:30 +01:00
|
|
|
assertNull(island.getOwner());
|
2019-08-05 06:44:46 +02:00
|
|
|
verify(pim).callEvent(any(IslandDeleteEvent.class));
|
2019-01-13 02:12:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#deleteIsland(world.bentobox.bentobox.database.objects.Island, boolean)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testDeleteIslandIslandBooleanRemoveBlocks() {
|
2019-08-05 06:44:46 +02:00
|
|
|
verify(pim, never()).callEvent(any());
|
2019-01-13 02:12:30 +01:00
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
UUID owner = UUID.randomUUID();
|
|
|
|
Island island = im.createIsland(location, owner);
|
2019-06-27 04:03:56 +02:00
|
|
|
im.deleteIsland(island, true, owner);
|
2019-01-13 02:12:30 +01:00
|
|
|
assertNull(island.getOwner());
|
2019-08-05 06:44:46 +02:00
|
|
|
verify(pim).callEvent(any(IslandDeleteEvent.class));
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-27 16:52:07 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIslandCount()}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetCount() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-10-27 16:52:07 +02:00
|
|
|
assertTrue(im.getIslandCount() == 0);
|
2018-05-06 07:26:25 +02:00
|
|
|
im.createIsland(location, UUID.randomUUID());
|
2018-10-27 16:52:07 +02:00
|
|
|
assertTrue(im.getIslandCount() == 1);
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-01 11:21:29 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIsland(World, UUID)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetIsland() {
|
|
|
|
UUID owner = UUID.randomUUID();
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
Island island = im.createIsland(location, owner);
|
2018-05-18 06:25:12 +02:00
|
|
|
assertEquals(island, im.getIsland(world, owner));
|
|
|
|
assertNull(im.getIsland(world, UUID.randomUUID()));
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIslandAt(org.bukkit.Location)}.
|
2018-06-25 01:22:44 +02:00
|
|
|
* @throws Exception
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetIslandAtLocation() throws Exception {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-08-04 18:37:21 +02:00
|
|
|
im.setIslandCache(islandCache);
|
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
// In world, correct island
|
2018-08-04 18:37:21 +02:00
|
|
|
assertEquals(optionalIsland, im.getIslandAt(location));
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
// in world, wrong island
|
2019-08-05 06:44:46 +02:00
|
|
|
when(islandCache.getIslandAt(any(Location.class))).thenReturn(null);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertEquals(Optional.empty(), im.getIslandAt(new Location(world, 100000, 120, -100000)));
|
|
|
|
|
|
|
|
// not in world
|
2018-09-29 18:01:20 +02:00
|
|
|
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
|
|
|
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertEquals(Optional.empty(), im.getIslandAt(new Location(world, 100000, 120, -100000)));
|
|
|
|
assertEquals(Optional.empty(), im.getIslandAt(location));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-01 11:21:29 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIslandLocation(World, UUID)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetIslandLocation() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-05-18 06:25:12 +02:00
|
|
|
im.createIsland(location, uuid);
|
2018-06-24 00:45:09 +02:00
|
|
|
assertEquals(world, im.getIslandLocation(world, uuid).getWorld());
|
2018-05-18 06:25:12 +02:00
|
|
|
assertNull(im.getIslandLocation(world, UUID.randomUUID()));
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-01 11:21:29 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getLast(World)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetLast() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
im.setLast(location);
|
2018-05-18 06:25:12 +02:00
|
|
|
assertEquals(location, im.getLast(world));
|
|
|
|
assertNull(im.getLast(null));
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-01 11:21:29 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getMembers(World, UUID)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
2019-01-18 11:33:29 +01:00
|
|
|
public void testGetMembers() {
|
2018-05-06 07:26:25 +02:00
|
|
|
// Mock island cache
|
|
|
|
Set<UUID> members = new HashSet<>();
|
|
|
|
members.add(UUID.randomUUID());
|
|
|
|
members.add(UUID.randomUUID());
|
|
|
|
members.add(UUID.randomUUID());
|
2019-08-05 06:44:46 +02:00
|
|
|
when(islandCache.getMembers(any(), any(), Mockito.anyInt())).thenReturn(members);
|
2018-05-06 07:26:25 +02:00
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-08-04 18:37:21 +02:00
|
|
|
im.setIslandCache(islandCache);
|
2018-05-18 06:25:12 +02:00
|
|
|
assertEquals(members, im.getMembers(world, UUID.randomUUID()));
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getProtectedIslandAt(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
2019-01-18 11:33:29 +01:00
|
|
|
public void testGetProtectedIslandAt() {
|
2018-05-06 07:26:25 +02:00
|
|
|
// Mock island cache
|
|
|
|
Island is = mock(Island.class);
|
|
|
|
|
2019-08-05 06:44:46 +02:00
|
|
|
when(islandCache.getIslandAt(any(Location.class))).thenReturn(is);
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
// In world
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-08-04 18:37:21 +02:00
|
|
|
im.setIslandCache(islandCache);
|
|
|
|
|
|
|
|
Optional<Island> optionalIsland = Optional.ofNullable(is);
|
2018-05-06 07:26:25 +02:00
|
|
|
// In world, correct island
|
2019-08-05 06:44:46 +02:00
|
|
|
when(is.onIsland(any())).thenReturn(true);
|
2018-08-04 18:37:21 +02:00
|
|
|
assertEquals(optionalIsland, im.getProtectedIslandAt(location));
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
// Not in protected space
|
2019-08-05 06:44:46 +02:00
|
|
|
when(is.onIsland(any())).thenReturn(false);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertEquals(Optional.empty(), im.getProtectedIslandAt(location));
|
|
|
|
|
|
|
|
im.setSpawn(is);
|
|
|
|
// In world, correct island
|
2019-08-05 06:44:46 +02:00
|
|
|
when(is.onIsland(any())).thenReturn(true);
|
2018-08-04 18:37:21 +02:00
|
|
|
assertEquals(optionalIsland, im.getProtectedIslandAt(location));
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
// Not in protected space
|
2019-08-05 06:44:46 +02:00
|
|
|
when(is.onIsland(any())).thenReturn(false);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertEquals(Optional.empty(), im.getProtectedIslandAt(location));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-01 11:21:29 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSafeHomeLocation(World, User, int)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetSafeHomeLocation() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2019-08-05 06:44:46 +02:00
|
|
|
when(pm.getHomeLocation(any(), any(User.class), eq(0))).thenReturn(null);
|
|
|
|
when(pm.getHomeLocation(any(), any(User.class), eq(1))).thenReturn(location);
|
2018-05-18 06:25:12 +02:00
|
|
|
assertEquals(location, im.getSafeHomeLocation(world, user, 0));
|
2018-05-06 07:26:25 +02:00
|
|
|
// Change location so that it is not safe
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2020-04-25 14:40:47 +02:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSafeHomeLocation(World, User, int)}.
|
|
|
|
* Ensures that the method returns {@code null} if the world is not an island world.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetSafeHomeLocationWorldNotIslandWorld() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
when(iwm.inWorld(world)).thenReturn(false);
|
|
|
|
assertNull(im.getSafeHomeLocation(world, user, 0));
|
|
|
|
}
|
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
/**
|
2018-08-01 11:21:29 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSpawnPoint(World)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetSpawnPoint() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-05-18 06:25:12 +02:00
|
|
|
assertNull(im.getSpawnPoint(world));
|
|
|
|
// Create a spawn island for this world
|
2018-05-06 07:26:25 +02:00
|
|
|
Island island = mock(Island.class);
|
2018-05-18 06:25:12 +02:00
|
|
|
when(island.getWorld()).thenReturn(world);
|
|
|
|
// Make a spawn position on the island
|
2019-08-05 06:44:46 +02:00
|
|
|
when(island.getSpawnPoint(any())).thenReturn(location);
|
2018-05-18 06:25:12 +02:00
|
|
|
// Set the spawn island
|
2018-05-06 07:26:25 +02:00
|
|
|
im.setSpawn(island);
|
2018-05-18 06:25:12 +02:00
|
|
|
assertEquals(location,im.getSpawnPoint(world));
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-01 11:21:29 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#homeTeleport(World, Player, int)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
2020-06-07 02:01:09 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2018-05-06 07:26:25 +02:00
|
|
|
@Test
|
|
|
|
public void testHomeTeleportPlayerInt() {
|
2018-06-25 01:22:44 +02:00
|
|
|
when(iwm.getDefaultGameMode(world)).thenReturn(GameMode.SURVIVAL);
|
2018-05-06 07:26:25 +02:00
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2019-08-05 06:44:46 +02:00
|
|
|
when(pm.getHomeLocation(any(), any(User.class), eq(0))).thenReturn(null);
|
|
|
|
when(pm.getHomeLocation(any(), any(User.class), eq(1))).thenReturn(location);
|
2018-05-18 06:25:12 +02:00
|
|
|
im.homeTeleport(world, player, 0);
|
2019-11-14 00:10:33 +01:00
|
|
|
verify(player).teleport(eq(location), any());
|
2018-06-25 01:22:44 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isAtSpawn(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testIsAtSpawn() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
assertFalse(im.isAtSpawn(location));
|
|
|
|
Island island = mock(Island.class);
|
2018-05-18 06:25:12 +02:00
|
|
|
when(island.getWorld()).thenReturn(world);
|
2019-08-05 06:44:46 +02:00
|
|
|
when(island.onIsland(any())).thenReturn(true);
|
2018-05-06 07:26:25 +02:00
|
|
|
im.setSpawn(island);
|
|
|
|
assertTrue(im.isAtSpawn(location));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-01 11:21:29 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isOwner(World, UUID)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
2019-01-18 11:33:29 +01:00
|
|
|
public void testIsOwner() {
|
2018-05-06 07:26:25 +02:00
|
|
|
// Mock island cache
|
|
|
|
Island is = mock(Island.class);
|
|
|
|
|
2019-08-05 06:44:46 +02:00
|
|
|
when(islandCache.getIslandAt(any())).thenReturn(is);
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-08-04 18:37:21 +02:00
|
|
|
im.setIslandCache(islandCache);
|
|
|
|
|
2018-05-18 06:25:12 +02:00
|
|
|
assertFalse(im.isOwner(world, null));
|
2018-05-06 07:26:25 +02:00
|
|
|
|
2019-08-05 06:44:46 +02:00
|
|
|
when(islandCache.hasIsland(any(), any())).thenReturn(false);
|
2018-05-18 06:25:12 +02:00
|
|
|
assertFalse(im.isOwner(world, UUID.randomUUID()));
|
2018-05-06 07:26:25 +02:00
|
|
|
|
2019-08-05 06:44:46 +02:00
|
|
|
when(islandCache.hasIsland(any(), any())).thenReturn(true);
|
|
|
|
when(islandCache.get(any(), any(UUID.class))).thenReturn(is);
|
2018-05-06 07:26:25 +02:00
|
|
|
UUID owner = UUID.randomUUID();
|
|
|
|
when(is.getOwner()).thenReturn(owner);
|
|
|
|
UUID notOwner = UUID.randomUUID();
|
|
|
|
while (owner.equals(notOwner)) {
|
|
|
|
notOwner = UUID.randomUUID();
|
|
|
|
}
|
2018-05-18 06:25:12 +02:00
|
|
|
assertFalse(im.isOwner(world, notOwner));
|
|
|
|
assertTrue(im.isOwner(world, owner));
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#load()}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testLoad() {
|
2018-06-25 02:57:31 +02:00
|
|
|
//IslandsManager im = new IslandsManager(plugin);
|
|
|
|
//im.load();
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#locationIsOnIsland(org.bukkit.entity.Player, org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
2019-01-18 11:33:29 +01:00
|
|
|
public void testLocationIsOnIsland() {
|
2018-05-06 07:26:25 +02:00
|
|
|
// Mock island cache
|
|
|
|
Island is = mock(Island.class);
|
|
|
|
|
2019-08-05 06:44:46 +02:00
|
|
|
when(islandCache.getIslandAt(any(Location.class))).thenReturn(is);
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
// In world
|
2019-08-05 06:44:46 +02:00
|
|
|
when(is.onIsland(any())).thenReturn(true);
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
Builder<UUID> members = new ImmutableSet.Builder<>();
|
|
|
|
members.add(uuid);
|
|
|
|
when(is.getMemberSet()).thenReturn(members.build());
|
|
|
|
|
|
|
|
when(player.getUniqueId()).thenReturn(uuid);
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-08-04 18:37:21 +02:00
|
|
|
im.setIslandCache(islandCache);
|
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
assertFalse(im.locationIsOnIsland(null, null));
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
assertTrue(im.locationIsOnIsland(player, location));
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
// No members
|
|
|
|
Builder<UUID> mem = new ImmutableSet.Builder<>();
|
|
|
|
when(is.getMemberSet()).thenReturn(mem.build());
|
|
|
|
assertFalse(im.locationIsOnIsland(player, location));
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-05-06 07:26:25 +02:00
|
|
|
// Not on island
|
|
|
|
when(is.getMemberSet()).thenReturn(members.build());
|
2019-08-05 06:44:46 +02:00
|
|
|
when(is.onIsland(any())).thenReturn(false);
|
2018-05-06 07:26:25 +02:00
|
|
|
assertFalse(im.locationIsOnIsland(player, location));
|
2018-04-05 04:25:13 +02:00
|
|
|
}
|
2018-05-06 07:26:25 +02:00
|
|
|
|
|
|
|
/**
|
2018-11-01 16:34:19 +01:00
|
|
|
* Test method for {@link IslandsManager#userIsOnIsland(World, User)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
2018-11-01 16:34:19 +01:00
|
|
|
public void testUserIsOnIsland() {
|
2018-05-06 07:26:25 +02:00
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-08-04 18:37:21 +02:00
|
|
|
im.setIslandCache(islandCache);
|
|
|
|
|
2018-11-01 16:34:19 +01:00
|
|
|
// ----- CHECK INVALID ARGUMENTS -----
|
|
|
|
|
2018-09-03 05:45:31 +02:00
|
|
|
// Null user
|
2018-05-18 06:25:12 +02:00
|
|
|
assertFalse(im.userIsOnIsland(world, null));
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-11-01 16:34:19 +01:00
|
|
|
// Null world
|
|
|
|
assertFalse(im.userIsOnIsland(null, user));
|
|
|
|
|
|
|
|
// Both null user and null world
|
|
|
|
assertFalse(im.userIsOnIsland(null, null));
|
|
|
|
|
|
|
|
// User is not a player
|
|
|
|
when(user.isPlayer()).thenReturn(false);
|
|
|
|
assertFalse(im.userIsOnIsland(world, user));
|
|
|
|
|
|
|
|
// ----- CHECK MEMBERSHIP -----
|
|
|
|
// We assume there that the User is in the good World.
|
|
|
|
when(user.getLocation().getWorld()).thenReturn(world);
|
|
|
|
when(user.isPlayer()).thenReturn(true);
|
2018-06-25 01:22:44 +02:00
|
|
|
|
2018-11-01 16:34:19 +01:00
|
|
|
// The method returns true if the user's location is on an island that has them as member (rank >= MEMBER)
|
2019-08-05 06:44:46 +02:00
|
|
|
when(is.onIsland(any())).thenReturn(true);
|
2018-09-03 05:45:31 +02:00
|
|
|
Map<UUID, Integer> members = new HashMap<>();
|
|
|
|
when(is.getMembers()).thenReturn(members);
|
2018-11-01 16:34:19 +01:00
|
|
|
|
|
|
|
// -- The user is not part of the island --
|
2018-09-03 05:45:31 +02:00
|
|
|
assertFalse(im.userIsOnIsland(world, user));
|
|
|
|
|
2018-11-01 16:34:19 +01:00
|
|
|
// -- The user is the owner of the island --
|
|
|
|
members.put(user.getUniqueId(), RanksManager.OWNER_RANK);
|
2018-06-25 01:22:44 +02:00
|
|
|
assertTrue(im.userIsOnIsland(world, user));
|
2018-09-03 05:45:31 +02:00
|
|
|
|
2018-11-01 16:34:19 +01:00
|
|
|
// Add some members to see if it still works
|
2018-10-30 21:21:27 +01:00
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
assertTrue(im.userIsOnIsland(world, user));
|
|
|
|
|
2018-11-01 16:34:19 +01:00
|
|
|
// Add some other ranks to see if it still works
|
2018-10-30 21:21:27 +01:00
|
|
|
members.put(UUID.randomUUID(), RanksManager.BANNED_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.BANNED_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.COOP_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.TRUSTED_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.BANNED_RANK);
|
|
|
|
assertTrue(im.userIsOnIsland(world, user));
|
|
|
|
|
2018-11-01 16:34:19 +01:00
|
|
|
// -- The user is a sub-owner on the island --
|
|
|
|
members.put(user.getUniqueId(), RanksManager.SUB_OWNER_RANK);
|
|
|
|
assertTrue(im.userIsOnIsland(world, user));
|
|
|
|
|
|
|
|
// -- The user is a member on the island --
|
|
|
|
members.put(user.getUniqueId(), RanksManager.MEMBER_RANK);
|
|
|
|
assertTrue(im.userIsOnIsland(world, user));
|
|
|
|
|
|
|
|
// -- The user is a trusted on the island --
|
|
|
|
members.put(user.getUniqueId(), RanksManager.TRUSTED_RANK);
|
|
|
|
assertTrue(im.userIsOnIsland(world, user));
|
|
|
|
|
|
|
|
// -- The user is a coop on the island --
|
|
|
|
members.put(user.getUniqueId(), RanksManager.COOP_RANK);
|
|
|
|
assertTrue(im.userIsOnIsland(world, user));
|
|
|
|
|
|
|
|
// -- The user is a visitor on the island --
|
|
|
|
members.remove(user.getUniqueId());
|
|
|
|
assertFalse(im.userIsOnIsland(world, user));
|
|
|
|
|
|
|
|
// -- The user is explicitly a visitor on the island --
|
|
|
|
members.put(user.getUniqueId(), RanksManager.VISITOR_RANK);
|
|
|
|
assertFalse(im.userIsOnIsland(world, user));
|
|
|
|
|
|
|
|
// -- The user is banned from the island --
|
2018-09-03 05:45:31 +02:00
|
|
|
members.put(user.getUniqueId(), RanksManager.BANNED_RANK);
|
|
|
|
assertFalse(im.userIsOnIsland(world, user));
|
2018-11-01 16:34:19 +01:00
|
|
|
|
|
|
|
// ----- CHECK WORLD -----
|
|
|
|
// Assertions above succeeded, so let's check that again with the User being a MEMBER and being in the wrong world.
|
|
|
|
when(user.getLocation().getWorld()).thenReturn(mock(World.class));
|
|
|
|
members.put(user.getUniqueId(), RanksManager.MEMBER_RANK);
|
|
|
|
assertFalse(im.userIsOnIsland(world, user));
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-01 11:21:29 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#removePlayer(World, User)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testRemovePlayer() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
2018-05-18 06:25:12 +02:00
|
|
|
im.removePlayer(world, uuid);
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#removePlayersFromIsland(world.bentobox.bentobox.database.objects.Island)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testRemovePlayersFromIsland() {
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
Island is = mock(Island.class);
|
|
|
|
im.removePlayersFromIsland(is);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-01-18 11:33:29 +01:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#save(Island)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testSave() {
|
2018-06-25 02:57:31 +02:00
|
|
|
//fail("Not yet implemented"); // TODO - warning saving stuff will go on the file system
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-05 06:50:10 +02:00
|
|
|
* Test method for .
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testSetIslandName() {
|
|
|
|
//fail("Not yet implemented"); // TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#setJoinTeam(world.bentobox.bentobox.database.objects.Island, java.util.UUID)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testSetJoinTeam() {
|
|
|
|
//fail("Not yet implemented"); // TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#setLast(org.bukkit.Location)}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testSetLast() {
|
|
|
|
//fail("Not yet implemented"); // TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-05 06:50:10 +02:00
|
|
|
* Test method for .
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testSetLeaveTeam() {
|
|
|
|
//fail("Not yet implemented"); // TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#shutdown()}.
|
2018-05-06 07:26:25 +02:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testShutdown() {
|
2018-11-20 21:52:12 +01:00
|
|
|
// Mock island cache
|
|
|
|
Island is = mock(Island.class);
|
|
|
|
|
|
|
|
Collection<Island> collection = new ArrayList<>();
|
|
|
|
collection.add(is);
|
|
|
|
when(islandCache.getIslands()).thenReturn(collection);
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
im.setIslandCache(islandCache);
|
|
|
|
Map<UUID, Integer> members = new HashMap<>();
|
|
|
|
when(is.getMembers()).thenReturn(members);
|
|
|
|
// -- The user is the owner of the island --
|
|
|
|
members.put(user.getUniqueId(), RanksManager.OWNER_RANK);
|
|
|
|
// Add some members
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
// Add some coops
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.COOP_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.COOP_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.COOP_RANK);
|
|
|
|
// Add some trusted
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.TRUSTED_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.TRUSTED_RANK);
|
|
|
|
|
|
|
|
im.shutdown();
|
|
|
|
|
|
|
|
assertEquals(10, members.size());
|
2019-08-05 06:44:46 +02:00
|
|
|
verify(islandCache).clear();
|
2018-11-20 21:52:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#clearRank(int, UUID)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testClearRank() {
|
|
|
|
// Mock island cache
|
|
|
|
Island is = mock(Island.class);
|
|
|
|
|
|
|
|
Collection<Island> collection = new ArrayList<>();
|
|
|
|
collection.add(is);
|
|
|
|
when(islandCache.getIslands()).thenReturn(collection);
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
im.setIslandCache(islandCache);
|
|
|
|
Map<UUID, Integer> members = new HashMap<>();
|
|
|
|
when(is.getMembers()).thenReturn(members);
|
|
|
|
// -- The user is the owner of the island --
|
|
|
|
members.put(user.getUniqueId(), RanksManager.OWNER_RANK);
|
|
|
|
// Add some members
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.MEMBER_RANK);
|
|
|
|
// Add some coops
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.COOP_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.COOP_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.COOP_RANK);
|
|
|
|
// Add some trusted
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.TRUSTED_RANK);
|
|
|
|
members.put(UUID.randomUUID(), RanksManager.TRUSTED_RANK);
|
|
|
|
// Add specific coop
|
|
|
|
UUID coopUUID = UUID.randomUUID();
|
|
|
|
members.put(coopUUID, RanksManager.COOP_RANK);
|
|
|
|
// Clear a random user
|
|
|
|
im.clearRank(RanksManager.COOP_RANK, UUID.randomUUID());
|
|
|
|
assertEquals(14, members.size());
|
|
|
|
im.clearRank(RanksManager.COOP_RANK, coopUUID);
|
|
|
|
assertEquals(13, members.size());
|
2018-05-06 07:26:25 +02:00
|
|
|
}
|
|
|
|
|
2018-06-25 02:57:31 +02:00
|
|
|
/**
|
2018-07-31 18:03:32 +02:00
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#clearArea(Location)}.
|
2018-06-25 02:57:31 +02:00
|
|
|
*/
|
|
|
|
@Test
|
2019-07-19 06:58:16 +02:00
|
|
|
public void testClearAreaWrongWorld() {
|
|
|
|
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
im.clearArea(location);
|
|
|
|
// No entities should be cleared
|
2019-08-05 06:44:46 +02:00
|
|
|
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();
|
2018-06-25 02:57:31 +02:00
|
|
|
|
2019-07-19 06:58:16 +02:00
|
|
|
}
|
2018-06-25 02:57:31 +02:00
|
|
|
|
2019-07-19 06:58:16 +02:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#clearArea(Location)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testClearArea() {
|
2018-06-25 02:57:31 +02:00
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
im.clearArea(location);
|
2019-07-19 06:58:16 +02:00
|
|
|
// Only the correct entities should be cleared
|
2019-08-05 06:44:46 +02:00
|
|
|
verify(zombie).remove();
|
|
|
|
verify(player, never()).remove();
|
|
|
|
verify(cow, never()).remove();
|
|
|
|
verify(slime).remove();
|
|
|
|
verify(wither, never()).remove();
|
|
|
|
verify(creeper).remove();
|
|
|
|
verify(pufferfish, never()).remove();
|
|
|
|
verify(skelly, never()).remove();
|
2018-06-25 02:57:31 +02:00
|
|
|
}
|
2019-02-12 04:01:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIslandById(String)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testGetIslandByIdString() {
|
|
|
|
Island island = mock(Island.class);
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
2019-08-05 06:44:46 +02:00
|
|
|
when(islandCache.getIslandById(anyString())).thenReturn(island);
|
2019-02-12 04:01:44 +01:00
|
|
|
// Test
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
im.setIslandCache(islandCache);
|
|
|
|
assertEquals(island, im.getIslandById(uuid).get());
|
|
|
|
}
|
2019-02-21 06:42:43 +01:00
|
|
|
|
2020-02-04 21:20:31 +01:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#fixIslandCenter(Island)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testFixIslandCenter() {
|
|
|
|
Island island = mock(Island.class);
|
|
|
|
when(island.getWorld()).thenReturn(world);
|
|
|
|
// Island center
|
|
|
|
when(location.getBlockX()).thenReturn(0);
|
|
|
|
when(location.getBlockY()).thenReturn(120);
|
|
|
|
when(location.getBlockZ()).thenReturn(0);
|
|
|
|
when(island.getCenter()).thenReturn(location);
|
|
|
|
// Start x,z
|
|
|
|
when(iwm.getIslandStartX(eq(world))).thenReturn(0);
|
|
|
|
when(iwm.getIslandStartZ(eq(world))).thenReturn(0);
|
|
|
|
// Offset x,z
|
|
|
|
when(iwm.getIslandXOffset(eq(world))).thenReturn(0);
|
|
|
|
when(iwm.getIslandZOffset(eq(world))).thenReturn(0);
|
|
|
|
// World
|
|
|
|
when(iwm.inWorld(eq(world))).thenReturn(true);
|
|
|
|
// Island distance
|
|
|
|
when(iwm.getIslandDistance(eq(world))).thenReturn(100);
|
|
|
|
// Test
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
assertFalse(im.fixIslandCenter(island));
|
|
|
|
}
|
2020-04-23 03:25:10 +02:00
|
|
|
|
2020-02-04 21:20:31 +01:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#fixIslandCenter(Island)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testFixIslandCenterOff() {
|
|
|
|
Island island = mock(Island.class);
|
|
|
|
when(island.getWorld()).thenReturn(world);
|
|
|
|
// Island center
|
|
|
|
when(location.getBlockX()).thenReturn(10);
|
|
|
|
when(location.getBlockY()).thenReturn(120);
|
|
|
|
when(location.getBlockZ()).thenReturn(-10);
|
|
|
|
when(island.getCenter()).thenReturn(location);
|
|
|
|
// Start x,z
|
|
|
|
when(iwm.getIslandStartX(eq(world))).thenReturn(0);
|
|
|
|
when(iwm.getIslandStartZ(eq(world))).thenReturn(0);
|
|
|
|
// Offset x,z
|
|
|
|
when(iwm.getIslandXOffset(eq(world))).thenReturn(0);
|
|
|
|
when(iwm.getIslandZOffset(eq(world))).thenReturn(0);
|
|
|
|
// World
|
|
|
|
when(iwm.inWorld(eq(world))).thenReturn(true);
|
|
|
|
// Island distance
|
|
|
|
when(iwm.getIslandDistance(eq(world))).thenReturn(100);
|
|
|
|
// Test
|
|
|
|
ArgumentCaptor<Location> captor = ArgumentCaptor.forClass(Location.class);
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
assertTrue(im.fixIslandCenter(island));
|
|
|
|
// Verify location
|
|
|
|
verify(island).setCenter(captor.capture());
|
|
|
|
assertEquals(world, captor.getValue().getWorld());
|
|
|
|
assertEquals(0, captor.getValue().getBlockX());
|
|
|
|
assertEquals(120, captor.getValue().getBlockY());
|
|
|
|
assertEquals(0, captor.getValue().getBlockZ());
|
2020-04-23 03:25:10 +02:00
|
|
|
|
2020-02-04 21:20:31 +01:00
|
|
|
}
|
2020-04-23 03:25:10 +02:00
|
|
|
|
2020-02-04 21:20:31 +01:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#fixIslandCenter(Island)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testFixIslandCenterOffStart() {
|
|
|
|
Island island = mock(Island.class);
|
|
|
|
when(island.getWorld()).thenReturn(world);
|
|
|
|
// Island center
|
|
|
|
when(location.getBlockX()).thenReturn(100010);
|
|
|
|
when(location.getBlockY()).thenReturn(120);
|
|
|
|
when(location.getBlockZ()).thenReturn(8755);
|
|
|
|
when(island.getCenter()).thenReturn(location);
|
|
|
|
// Start x,z
|
|
|
|
when(iwm.getIslandStartX(eq(world))).thenReturn(100000);
|
|
|
|
when(iwm.getIslandStartZ(eq(world))).thenReturn(8765);
|
|
|
|
// Offset x,z
|
|
|
|
when(iwm.getIslandXOffset(eq(world))).thenReturn(0);
|
|
|
|
when(iwm.getIslandZOffset(eq(world))).thenReturn(0);
|
|
|
|
// World
|
|
|
|
when(iwm.inWorld(eq(world))).thenReturn(true);
|
|
|
|
// Island distance
|
|
|
|
when(iwm.getIslandDistance(eq(world))).thenReturn(100);
|
|
|
|
// Test
|
|
|
|
ArgumentCaptor<Location> captor = ArgumentCaptor.forClass(Location.class);
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
assertTrue(im.fixIslandCenter(island));
|
|
|
|
// Verify location
|
|
|
|
verify(island).setCenter(captor.capture());
|
|
|
|
assertEquals(world, captor.getValue().getWorld());
|
|
|
|
assertEquals(100000, captor.getValue().getBlockX());
|
|
|
|
assertEquals(120, captor.getValue().getBlockY());
|
|
|
|
assertEquals(8765, captor.getValue().getBlockZ());
|
2020-04-23 03:25:10 +02:00
|
|
|
|
2020-02-04 21:20:31 +01:00
|
|
|
}
|
2020-04-23 03:25:10 +02:00
|
|
|
|
2020-02-04 21:20:31 +01:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#fixIslandCenter(Island)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testFixIslandCenterStartOnGrid() {
|
|
|
|
Island island = mock(Island.class);
|
|
|
|
when(island.getWorld()).thenReturn(world);
|
|
|
|
// Island center
|
|
|
|
when(location.getBlockX()).thenReturn(10000);
|
|
|
|
when(location.getBlockY()).thenReturn(120);
|
|
|
|
when(location.getBlockZ()).thenReturn(8765);
|
|
|
|
when(island.getCenter()).thenReturn(location);
|
|
|
|
// Start x,z
|
|
|
|
when(iwm.getIslandStartX(eq(world))).thenReturn(100000);
|
|
|
|
when(iwm.getIslandStartZ(eq(world))).thenReturn(8765);
|
|
|
|
// Offset x,z
|
|
|
|
when(iwm.getIslandXOffset(eq(world))).thenReturn(0);
|
|
|
|
when(iwm.getIslandZOffset(eq(world))).thenReturn(0);
|
|
|
|
// World
|
|
|
|
when(iwm.inWorld(eq(world))).thenReturn(true);
|
|
|
|
// Island distance
|
|
|
|
when(iwm.getIslandDistance(eq(world))).thenReturn(100);
|
|
|
|
// Test
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
assertFalse(im.fixIslandCenter(island));
|
|
|
|
}
|
2020-04-23 03:25:10 +02:00
|
|
|
|
2020-02-04 21:20:31 +01:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#fixIslandCenter(Island)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testFixIslandCenterStartOnGridOffset() {
|
|
|
|
Island island = mock(Island.class);
|
|
|
|
when(island.getWorld()).thenReturn(world);
|
|
|
|
// Island center
|
|
|
|
when(location.getBlockX()).thenReturn(10050);
|
|
|
|
when(location.getBlockY()).thenReturn(120);
|
|
|
|
when(location.getBlockZ()).thenReturn(8815);
|
|
|
|
when(island.getCenter()).thenReturn(location);
|
|
|
|
// Start x,z
|
|
|
|
when(iwm.getIslandStartX(eq(world))).thenReturn(100000);
|
|
|
|
when(iwm.getIslandStartZ(eq(world))).thenReturn(8765);
|
|
|
|
// Offset x,z
|
|
|
|
when(iwm.getIslandXOffset(eq(world))).thenReturn(50);
|
|
|
|
when(iwm.getIslandZOffset(eq(world))).thenReturn(50);
|
|
|
|
// World
|
|
|
|
when(iwm.inWorld(eq(world))).thenReturn(true);
|
|
|
|
// Island distance
|
|
|
|
when(iwm.getIslandDistance(eq(world))).thenReturn(100);
|
|
|
|
// Test
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
assertFalse(im.fixIslandCenter(island));
|
|
|
|
}
|
2020-04-23 03:25:10 +02:00
|
|
|
|
2020-02-04 21:20:31 +01:00
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#fixIslandCenter(Island)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testFixIslandCenterOffStartOffOffset() {
|
|
|
|
Island island = mock(Island.class);
|
|
|
|
when(island.getWorld()).thenReturn(world);
|
|
|
|
// Island center
|
|
|
|
when(location.getBlockX()).thenReturn(100060);
|
|
|
|
when(location.getBlockY()).thenReturn(120);
|
|
|
|
when(location.getBlockZ()).thenReturn(8815);
|
|
|
|
when(island.getCenter()).thenReturn(location);
|
|
|
|
// Start x,z
|
|
|
|
when(iwm.getIslandStartX(eq(world))).thenReturn(100000);
|
|
|
|
when(iwm.getIslandStartZ(eq(world))).thenReturn(8765);
|
|
|
|
// Offset x,z
|
|
|
|
when(iwm.getIslandXOffset(eq(world))).thenReturn(50);
|
|
|
|
when(iwm.getIslandZOffset(eq(world))).thenReturn(50);
|
|
|
|
// World
|
|
|
|
when(iwm.inWorld(eq(world))).thenReturn(true);
|
|
|
|
// Island distance
|
|
|
|
when(iwm.getIslandDistance(eq(world))).thenReturn(100);
|
|
|
|
// Test
|
|
|
|
ArgumentCaptor<Location> captor = ArgumentCaptor.forClass(Location.class);
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
assertTrue(im.fixIslandCenter(island));
|
|
|
|
// Verify location
|
|
|
|
verify(island).setCenter(captor.capture());
|
|
|
|
assertEquals(world, captor.getValue().getWorld());
|
|
|
|
assertEquals(100050, captor.getValue().getBlockX());
|
|
|
|
assertEquals(120, captor.getValue().getBlockY());
|
|
|
|
assertEquals(8815, captor.getValue().getBlockZ());
|
2020-04-23 03:25:10 +02:00
|
|
|
|
2020-02-04 21:20:31 +01:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#fixIslandCenter(Island)}.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testFixIslandCenterNulls() {
|
|
|
|
Island island = mock(Island.class);
|
|
|
|
when(island.getWorld()).thenReturn(null);
|
|
|
|
// Test
|
|
|
|
IslandsManager im = new IslandsManager(plugin);
|
|
|
|
assertFalse(im.fixIslandCenter(island));
|
|
|
|
when(island.getWorld()).thenReturn(world);
|
|
|
|
when(island.getCenter()).thenReturn(null);
|
|
|
|
assertFalse(im.fixIslandCenter(island));
|
|
|
|
when(island.getCenter()).thenReturn(location);
|
|
|
|
when(iwm.inWorld(eq(world))).thenReturn(false);
|
|
|
|
assertFalse(im.fixIslandCenter(island));
|
|
|
|
}
|
2020-04-23 03:25:10 +02:00
|
|
|
|
2018-03-12 01:21:15 +01:00
|
|
|
}
|