mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 11:45:31 +01:00
Merge pull request #471 from BentoBoxWorld/locale-override
Adds ability for gamemodes to override locale references
This commit is contained in:
commit
9497066f44
@ -236,19 +236,25 @@ public class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a translation of this reference for this user.
|
* Gets a translation of this reference for this user. Translations may be overridden by Addons
|
||||||
|
* by using the same reference prefixed by the addon name (from the Addon Description) in lower case.
|
||||||
* @param reference - reference found in a locale file
|
* @param reference - reference found in a locale file
|
||||||
* @param variables - variables to insert into translated string. Variables go in pairs, for example
|
* @param variables - variables to insert into translated string. Variables go in pairs, for example
|
||||||
* "[name]", "tastybento"
|
* "[name]", "tastybento"
|
||||||
* @return Translated string with colors converted, or the reference if nothing has been found
|
* @return Translated string with colors converted, or the reference if nothing has been found
|
||||||
*/
|
*/
|
||||||
public String getTranslation(String reference, String... variables) {
|
public String getTranslation(String reference, String... variables) {
|
||||||
// Get translation
|
// Get translation.
|
||||||
String translation = plugin.getLocalesManager().get(this, reference);
|
String addonPrefix = plugin.getIWM()
|
||||||
|
.getAddon(getWorld()).map(a -> a.getDescription().getName().toLowerCase() + ".").orElse("");
|
||||||
|
String translation = plugin.getLocalesManager().get(this, addonPrefix + reference);
|
||||||
|
|
||||||
// If no translation has been found, return the reference for debug purposes.
|
|
||||||
if (translation == null) {
|
if (translation == null) {
|
||||||
return reference;
|
translation = plugin.getLocalesManager().get(this, reference);
|
||||||
|
if (translation == null) {
|
||||||
|
// If no translation has been found, return the reference for debug purposes.
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then replace variables
|
// Then replace variables
|
||||||
@ -327,10 +333,10 @@ public class User {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current world this entity resides in
|
* Gets the current world this entity resides in
|
||||||
* @return World
|
* @return World - world or null
|
||||||
*/
|
*/
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return player.getWorld();
|
return player == null ? null : player.getWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,17 +65,17 @@ public class EnterExitListener extends FlagListener {
|
|||||||
islandFrom.ifPresent(i -> {
|
islandFrom.ifPresent(i -> {
|
||||||
// Fire the IslandExitEvent
|
// Fire the IslandExitEvent
|
||||||
new IslandEvent.IslandEventBuilder()
|
new IslandEvent.IslandEventBuilder()
|
||||||
.island(i)
|
.island(i)
|
||||||
.involvedPlayer(user.getUniqueId())
|
.involvedPlayer(user.getUniqueId())
|
||||||
.reason(IslandEvent.Reason.EXIT)
|
.reason(IslandEvent.Reason.EXIT)
|
||||||
.admin(false)
|
.admin(false)
|
||||||
.location(user.getLocation())
|
.location(user.getLocation())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Send message if island is owned by someone
|
// Send message if island is owned by someone
|
||||||
if (i.getOwner() != null) {
|
if (i.getOwner() != null) {
|
||||||
user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, (i.getName() != null) ? i.getName() :
|
user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, (i.getName() != null) ? i.getName() :
|
||||||
user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(i.getOwner())));
|
user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(i.getOwner())));
|
||||||
}
|
}
|
||||||
// Send message if island is unowned, but has a name
|
// Send message if island is unowned, but has a name
|
||||||
else if (i.getName() != null) {
|
else if (i.getName() != null) {
|
||||||
@ -86,17 +86,17 @@ public class EnterExitListener extends FlagListener {
|
|||||||
islandTo.ifPresent(i -> {
|
islandTo.ifPresent(i -> {
|
||||||
// Fire the IslandEnterEvent
|
// Fire the IslandEnterEvent
|
||||||
new IslandEvent.IslandEventBuilder()
|
new IslandEvent.IslandEventBuilder()
|
||||||
.island(i)
|
.island(i)
|
||||||
.involvedPlayer(user.getUniqueId())
|
.involvedPlayer(user.getUniqueId())
|
||||||
.reason(IslandEvent.Reason.ENTER)
|
.reason(IslandEvent.Reason.ENTER)
|
||||||
.admin(false)
|
.admin(false)
|
||||||
.location(user.getLocation())
|
.location(user.getLocation())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Send message if island is owned by someone
|
// Send message if island is owned by someone
|
||||||
if (i.getOwner() != null) {
|
if (i.getOwner() != null) {
|
||||||
user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, (i.getName() != null) ? i.getName() :
|
user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, (i.getName() != null) ? i.getName() :
|
||||||
user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(i.getOwner())));
|
user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(i.getOwner())));
|
||||||
}
|
}
|
||||||
// Send message if island is unowned, but has a name
|
// Send message if island is unowned, but has a name
|
||||||
else if (i.getName() != null) {
|
else if (i.getName() != null) {
|
||||||
|
@ -168,8 +168,11 @@ public class AddonsManager {
|
|||||||
private void handleAddonError(Addon addon, Throwable throwable) {
|
private void handleAddonError(Addon addon, Throwable throwable) {
|
||||||
// Set the AddonState as "ERROR".
|
// Set the AddonState as "ERROR".
|
||||||
addon.setState(Addon.State.ERROR);
|
addon.setState(Addon.State.ERROR);
|
||||||
plugin.log("Skipping " + addon.getDescription().getName() + " due to an unhandled exception...");
|
plugin.logError("Skipping " + addon.getDescription().getName() + " due to an unhandled exception...");
|
||||||
plugin.log("STACKTRACE: " + throwable.getClass().getSimpleName() + " - " + throwable.getMessage() + " - " + throwable.getCause());
|
plugin.logError("STACKTRACE: " + throwable.getClass().getSimpleName() + " - " + throwable.getMessage() + " - " + throwable.getCause());
|
||||||
|
if (plugin.getConfig().getBoolean("debug")) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
@ -549,8 +550,8 @@ public class IslandWorldManager {
|
|||||||
* - world
|
* - world
|
||||||
* @return GameModeAddon, or empty
|
* @return GameModeAddon, or empty
|
||||||
*/
|
*/
|
||||||
public Optional<GameModeAddon> getAddon(World world) {
|
public Optional<GameModeAddon> getAddon(@Nullable World world) {
|
||||||
return Optional.ofNullable(gameModes.get(Util.getWorld(world)));
|
return world == null ? Optional.empty() : Optional.ofNullable(gameModes.get(Util.getWorld(world)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,6 +113,10 @@ public class AdminInfoCommandTest {
|
|||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -101,8 +102,11 @@ public class AdminRangeCommandTest {
|
|||||||
// Locales
|
// Locales
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
Answer<String> answer = invocation -> invocation.getArgumentAt(1, String.class);
|
Answer<String> answer = invocation -> invocation.getArgumentAt(1, String.class);
|
||||||
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,12 @@ package world.bentobox.bentobox.api.commands.admin.range;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -117,6 +122,8 @@ public class AdminRangeResetCommandTest {
|
|||||||
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,7 +6,12 @@ package world.bentobox.bentobox.api.commands.admin.range;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -119,6 +124,8 @@ public class AdminRangeSetCommandTest {
|
|||||||
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -110,6 +111,9 @@ public class AdminTeamAddCommandTest {
|
|||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -110,6 +111,9 @@ public class AdminTeamDisbandCommandTest {
|
|||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -112,6 +113,9 @@ public class AdminTeamKickCommandTest {
|
|||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,6 +121,9 @@ public class IslandTeamKickCommandTest {
|
|||||||
iwm = mock(IslandWorldManager.class);
|
iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,6 +11,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -27,26 +28,43 @@ import org.bukkit.inventory.ItemFactory;
|
|||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
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;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.api.addons.AddonDescription;
|
||||||
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
import world.bentobox.bentobox.managers.LocalesManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({ BentoBox.class, Bukkit.class })
|
||||||
public class UserTest {
|
public class UserTest {
|
||||||
|
|
||||||
private static Player player;
|
private static final String TEST_TRANSLATION = "mock translation [test]";
|
||||||
|
private Player player;
|
||||||
|
private BentoBox plugin;
|
||||||
|
private LocalesManager lm;
|
||||||
|
private User user;
|
||||||
|
private IslandWorldManager iwm;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
// Set up plugin
|
||||||
|
plugin = mock(BentoBox.class);
|
||||||
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
User.setPlugin(plugin);
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception {
|
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
World world = mock(World.class);
|
World world = mock(World.class);
|
||||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
@ -62,21 +80,35 @@ public class UserTest {
|
|||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
Bukkit.setServer(server);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPlayer(Mockito.any(UUID.class))).thenReturn(player);
|
||||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
|
|
||||||
|
iwm = mock(IslandWorldManager.class);
|
||||||
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
// Addon
|
||||||
|
when(iwm .getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
sender = mock(CommandSender.class);
|
||||||
|
|
||||||
|
user = User.getInstance(player);
|
||||||
|
|
||||||
|
// Locales
|
||||||
|
lm = mock(LocalesManager.class);
|
||||||
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
when(lm.get(any(), any())).thenReturn(TEST_TRANSLATION);
|
||||||
|
when(lm.get(any())).thenReturn(TEST_TRANSLATION);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanUp() {
|
||||||
|
User.clearUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandSender sender;
|
private CommandSender sender;
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
sender = mock(CommandSender.class);
|
|
||||||
User.clearUsers();
|
|
||||||
User.setPlugin(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetInstanceCommandSender() {
|
public void testGetInstanceCommandSender() {
|
||||||
@ -87,9 +119,6 @@ public class UserTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetInstancePlayer() {
|
public void testGetInstancePlayer() {
|
||||||
Player player = mock(Player.class);
|
|
||||||
User user = User.getInstance(player);
|
|
||||||
assertNotNull(user);
|
|
||||||
assertEquals(player,user.getPlayer());
|
assertEquals(player,user.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,14 +204,13 @@ public class UserTest {
|
|||||||
public void testGetUniqueId() {
|
public void testGetUniqueId() {
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
User user = User.getInstance(player);
|
user = User.getInstance(player);
|
||||||
assertEquals(uuid, user.getUniqueId());
|
assertEquals(uuid, user.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHasPermission() {
|
public void testHasPermission() {
|
||||||
when(player.hasPermission(Mockito.anyString())).thenReturn(true);
|
when(player.hasPermission(Mockito.anyString())).thenReturn(true);
|
||||||
User user = User.getInstance(player);
|
|
||||||
assertTrue(user.hasPermission(""));
|
assertTrue(user.hasPermission(""));
|
||||||
assertTrue(user.hasPermission("perm"));
|
assertTrue(user.hasPermission("perm"));
|
||||||
}
|
}
|
||||||
@ -190,27 +218,18 @@ public class UserTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsOnline() {
|
public void testIsOnline() {
|
||||||
when(player.isOnline()).thenReturn(true);
|
when(player.isOnline()).thenReturn(true);
|
||||||
User user = User.getInstance(player);
|
|
||||||
assertTrue(user.isOnline());
|
assertTrue(user.isOnline());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsOp() {
|
public void testIsOp() {
|
||||||
when(player.isOp()).thenReturn(true);
|
when(player.isOp()).thenReturn(true);
|
||||||
User user = User.getInstance(player);
|
|
||||||
assertTrue(user.isOp());
|
assertTrue(user.isOp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetTranslation() {
|
public void testGetTranslation() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
User.setPlugin(plugin);
|
|
||||||
// Locales - final
|
// Locales - final
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
|
||||||
when(lm.get(any(), any())).thenReturn("mock translation [test]");
|
|
||||||
|
|
||||||
User user = User.getInstance(player);
|
|
||||||
assertEquals("mock translation [test]", user.getTranslation("a.reference"));
|
assertEquals("mock translation [test]", user.getTranslation("a.reference"));
|
||||||
assertEquals("mock translation variable", user.getTranslation("a.reference", "[test]", "variable"));
|
assertEquals("mock translation variable", user.getTranslation("a.reference", "[test]", "variable"));
|
||||||
|
|
||||||
@ -222,13 +241,9 @@ public class UserTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetTranslationOrNothing() {
|
public void testGetTranslationOrNothing() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
User.setPlugin(plugin);
|
|
||||||
// Locales - final
|
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
|
||||||
// Return the original string to pretend that a translation could not be found
|
// Return the original string to pretend that a translation could not be found
|
||||||
when(lm.get(any(), any())).thenReturn("fake.reference");
|
when(lm.get(any(), any())).thenReturn("fake.reference");
|
||||||
|
when(lm.get(any())).thenReturn("fake.reference");
|
||||||
|
|
||||||
User user = User.getInstance(player);
|
User user = User.getInstance(player);
|
||||||
assertEquals("", user.getTranslationOrNothing("fake.reference"));
|
assertEquals("", user.getTranslationOrNothing("fake.reference"));
|
||||||
@ -237,67 +252,34 @@ public class UserTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendMessage() {
|
public void testSendMessage() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
User.setPlugin(plugin);
|
|
||||||
// Locales - final
|
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
|
||||||
String translation = ChatColor.RED + "" + ChatColor.BOLD + "test translation";
|
|
||||||
when(lm.get(any(), any())).thenReturn(translation);
|
|
||||||
|
|
||||||
Player pl = mock(Player.class);
|
|
||||||
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
user.sendMessage("a.reference");
|
user.sendMessage("a.reference");
|
||||||
Mockito.verify(pl).sendMessage(translation);
|
Mockito.verify(player).sendMessage(Mockito.eq(TEST_TRANSLATION));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendMessageNullUser() {
|
public void testSendMessageOverrideWithAddon() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
GameModeAddon addon = mock(GameModeAddon.class);
|
||||||
User.setPlugin(plugin);
|
AddonDescription desc = new AddonDescription.Builder("mock", "name").build();
|
||||||
// Locales - final
|
when(addon.getDescription()).thenReturn(desc);
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
Optional<GameModeAddon> optionalAddon = Optional.of(addon);
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(iwm .getAddon(any())).thenReturn(optionalAddon);
|
||||||
String translation = ChatColor.RED + "" + ChatColor.BOLD + "test translation";
|
when(lm.get(any(), Mockito.eq("name.a.reference"))).thenReturn("mockmockmock");
|
||||||
when(lm.get(any(), any())).thenReturn(translation);
|
|
||||||
|
|
||||||
Player pl = mock(Player.class);
|
|
||||||
|
|
||||||
User user = User.getInstance(UUID.randomUUID());
|
|
||||||
user.sendMessage("a.reference");
|
user.sendMessage("a.reference");
|
||||||
Mockito.verify(pl, Mockito.never()).sendMessage(Mockito.anyString());
|
Mockito.verify(player, Mockito.never()).sendMessage(Mockito.eq(TEST_TRANSLATION));
|
||||||
|
Mockito.verify(player).sendMessage(Mockito.eq("mockmockmock"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendMessageBlankTranslation() {
|
public void testSendMessageBlankTranslation() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
User.setPlugin(plugin);
|
|
||||||
// Locales - final
|
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
|
||||||
// Nothing - blank translation
|
// Nothing - blank translation
|
||||||
when(lm.get(any(), any())).thenReturn("");
|
when(lm.get(any(), any())).thenReturn("");
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
|
||||||
|
|
||||||
Player pl = mock(Player.class);
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
user.sendMessage("a.reference");
|
user.sendMessage("a.reference");
|
||||||
Mockito.verify(pl, Mockito.never()).sendMessage(Mockito.anyString());
|
Mockito.verify(player, Mockito.never()).sendMessage(Mockito.anyString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendMessageOnlyColors() {
|
public void testSendMessageOnlyColors() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
User.setPlugin(plugin);
|
|
||||||
// Locales - final
|
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
|
||||||
|
|
||||||
Player pl = mock(Player.class);
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
|
|
||||||
// Nothing - just color codes
|
// Nothing - just color codes
|
||||||
StringBuilder allColors = new StringBuilder();
|
StringBuilder allColors = new StringBuilder();
|
||||||
for (ChatColor cc : ChatColor.values()) {
|
for (ChatColor cc : ChatColor.values()) {
|
||||||
@ -305,57 +287,36 @@ public class UserTest {
|
|||||||
}
|
}
|
||||||
when(lm.get(any(), any())).thenReturn(allColors.toString());
|
when(lm.get(any(), any())).thenReturn(allColors.toString());
|
||||||
user.sendMessage("a.reference");
|
user.sendMessage("a.reference");
|
||||||
Mockito.verify(pl, Mockito.never()).sendMessage(Mockito.anyString());
|
Mockito.verify(player, Mockito.never()).sendMessage(Mockito.anyString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendRawMessage() {
|
public void testSendRawMessage() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
User.setPlugin(plugin);
|
|
||||||
String raw = ChatColor.RED + "" + ChatColor.BOLD + "test message";
|
String raw = ChatColor.RED + "" + ChatColor.BOLD + "test message";
|
||||||
|
|
||||||
Player pl = mock(Player.class);
|
|
||||||
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
user.sendRawMessage(raw);
|
user.sendRawMessage(raw);
|
||||||
Mockito.verify(pl).sendMessage(raw);
|
Mockito.verify(player).sendMessage(raw);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendRawMessageNullUser() {
|
public void testSendRawMessageNullUser() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
User.setPlugin(plugin);
|
|
||||||
String raw = ChatColor.RED + "" + ChatColor.BOLD + "test message";
|
String raw = ChatColor.RED + "" + ChatColor.BOLD + "test message";
|
||||||
|
user = User.getInstance((CommandSender)null);
|
||||||
Player pl = mock(Player.class);
|
|
||||||
|
|
||||||
User user = User.getInstance(UUID.randomUUID());
|
|
||||||
user.sendRawMessage(raw);
|
user.sendRawMessage(raw);
|
||||||
Mockito.verify(pl, Mockito.never()).sendMessage(Mockito.anyString());
|
Mockito.verify(player, Mockito.never()).sendMessage(Mockito.anyString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotifyStringStringArrayNotifyOK() {
|
public void testNotifyStringStringArrayNotifyOK() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
Notifier notifier = mock(Notifier.class);
|
Notifier notifier = mock(Notifier.class);
|
||||||
|
|
||||||
when(plugin.getNotifier()).thenReturn(notifier);
|
when(plugin.getNotifier()).thenReturn(notifier);
|
||||||
User.setPlugin(plugin);
|
|
||||||
// Locales - final
|
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
|
||||||
String translation = ChatColor.RED + "" + ChatColor.BOLD + "test translation";
|
String translation = ChatColor.RED + "" + ChatColor.BOLD + "test translation";
|
||||||
when(lm.get(any(), any())).thenReturn(translation);
|
when(lm.get(any(), any())).thenReturn(translation);
|
||||||
|
|
||||||
Player pl = mock(Player.class);
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
|
|
||||||
// Set notify
|
// Set notify
|
||||||
when(notifier.notify(Mockito.any(), Mockito.eq(translation))).thenReturn(true);
|
when(notifier.notify(any(), Mockito.eq(translation))).thenReturn(true);
|
||||||
|
|
||||||
user.notify("a.reference");
|
user.notify("a.reference");
|
||||||
Mockito.verify(notifier).notify(user, translation);
|
Mockito.verify(notifier).notify(user, translation);
|
||||||
@ -365,63 +326,49 @@ public class UserTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetGameMode() {
|
public void testSetGameMode() {
|
||||||
Player pl = mock(Player.class);
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
for (GameMode gm: GameMode.values()) {
|
for (GameMode gm: GameMode.values()) {
|
||||||
user.setGameMode(gm);
|
user.setGameMode(gm);
|
||||||
}
|
}
|
||||||
Mockito.verify(pl, Mockito.times(GameMode.values().length)).setGameMode(Mockito.any());
|
Mockito.verify(player, Mockito.times(GameMode.values().length)).setGameMode(Mockito.any());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTeleport() {
|
public void testTeleport() {
|
||||||
Player pl = mock(Player.class);
|
when(player.teleport(Mockito.any(Location.class))).thenReturn(true);
|
||||||
User user = User.getInstance(pl);
|
|
||||||
when(pl.teleport(Mockito.any(Location.class))).thenReturn(true);
|
|
||||||
Location loc = mock(Location.class);
|
Location loc = mock(Location.class);
|
||||||
user.teleport(loc);
|
user.teleport(loc);
|
||||||
Mockito.verify(pl).teleport(loc);
|
Mockito.verify(player).teleport(loc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetWorld() {
|
public void testGetWorld() {
|
||||||
Player pl = mock(Player.class);
|
|
||||||
World world = mock(World.class);
|
World world = mock(World.class);
|
||||||
when(pl.getWorld()).thenReturn(world);
|
when(player.getWorld()).thenReturn(world);
|
||||||
User user = User.getInstance(pl);
|
User user = User.getInstance(player);
|
||||||
assertEquals(world, user.getWorld());
|
assertEquals(world, user.getWorld());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloseInventory() {
|
public void testCloseInventory() {
|
||||||
Player pl = mock(Player.class);
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
user.closeInventory();
|
user.closeInventory();
|
||||||
Mockito.verify(pl).closeInventory();
|
Mockito.verify(player).closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLocalePlayer() {
|
public void testGetLocalePlayer() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
User.setPlugin(plugin);
|
|
||||||
PlayersManager pm = mock(PlayersManager.class);
|
PlayersManager pm = mock(PlayersManager.class);
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
when(pm.getLocale(Mockito.any())).thenReturn("en-US");
|
when(pm.getLocale(Mockito.any())).thenReturn("en-US");
|
||||||
|
|
||||||
// Confirm that Locale object is correctly obtained
|
// Confirm that Locale object is correctly obtained
|
||||||
Locale locale = Locale.US;
|
assertEquals(Locale.US, user.getLocale());
|
||||||
Player pl = mock(Player.class);
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
assertEquals(locale, user.getLocale());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLocaleConsole() {
|
public void testGetLocaleConsole() {
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
User.setPlugin(plugin);
|
|
||||||
PlayersManager pm = mock(PlayersManager.class);
|
PlayersManager pm = mock(PlayersManager.class);
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
when(pm.getLocale(Mockito.any())).thenReturn("en-US");
|
when(pm.getLocale(Mockito.any())).thenReturn("en-US");
|
||||||
@ -438,18 +385,14 @@ public class UserTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateInventory() {
|
public void testUpdateInventory() {
|
||||||
Player pl = mock(Player.class);
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
user.updateInventory();
|
user.updateInventory();
|
||||||
Mockito.verify(pl).updateInventory();
|
Mockito.verify(player).updateInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPerformCommand() {
|
public void testPerformCommand() {
|
||||||
Player pl = mock(Player.class);
|
|
||||||
User user = User.getInstance(pl);
|
|
||||||
user.performCommand("test");
|
user.performCommand("test");
|
||||||
Mockito.verify(pl).performCommand("test");
|
Mockito.verify(player).performCommand("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unlikely-arg-type")
|
@SuppressWarnings("unlikely-arg-type")
|
||||||
|
@ -10,6 +10,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -92,6 +93,9 @@ public class BannedVisitorCommandsTest {
|
|||||||
Notifier notifier = mock(Notifier.class);
|
Notifier notifier = mock(Notifier.class);
|
||||||
when(plugin.getNotifier()).thenReturn(notifier);
|
when(plugin.getNotifier()).thenReturn(notifier);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +148,10 @@ public class NetherPortalsTest {
|
|||||||
|
|
||||||
// Normally in world
|
// Normally in world
|
||||||
Util.setPlugin(plugin);
|
Util.setPlugin(plugin);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void wrongWorld() {
|
private void wrongWorld() {
|
||||||
|
@ -182,6 +182,10 @@ public class BreedingListenerTest {
|
|||||||
|
|
||||||
PowerMockito.mockStatic(Util.class);
|
PowerMockito.mockStatic(Util.class);
|
||||||
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
|
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,6 +131,9 @@ public class EnderChestListenerTest {
|
|||||||
item = mock(ItemStack.class);
|
item = mock(ItemStack.class);
|
||||||
clickedBlock = mock(Block.class);
|
clickedBlock = mock(Block.class);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -170,6 +170,10 @@ public class EnterExitListenerTest {
|
|||||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||||
Map<String, Boolean> worldFlags = new HashMap<>();
|
Map<String, Boolean> worldFlags = new HashMap<>();
|
||||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package world.bentobox.bentobox.listeners.flags;
|
package world.bentobox.bentobox.listeners.flags;
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( {Bukkit.class, BentoBox.class, Flags.class, Util.class} )
|
@PrepareForTest( {Bukkit.class, BentoBox.class, Flags.class, Util.class} )
|
||||||
public class ExperiencePickupListenerTest {
|
public class ExperiencePickupListenerTest {
|
||||||
|
|
||||||
private EntityTargetLivingEntityEvent e;
|
private EntityTargetLivingEntityEvent e;
|
||||||
private ExperiencePickupListener epl;
|
private ExperiencePickupListener epl;
|
||||||
private World world;
|
private World world;
|
||||||
@ -73,10 +73,10 @@ public class ExperiencePickupListenerTest {
|
|||||||
// Set up plugin
|
// Set up plugin
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
|
||||||
// World
|
// World
|
||||||
world = mock(World.class);
|
world = mock(World.class);
|
||||||
|
|
||||||
//FlagsManager flagsManager = new FlagsManager(plugin);
|
//FlagsManager flagsManager = new FlagsManager(plugin);
|
||||||
//when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
//when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class ExperiencePickupListenerTest {
|
|||||||
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(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Fake players
|
// Fake players
|
||||||
Settings settings = mock(Settings.class);
|
Settings settings = mock(Settings.class);
|
||||||
Mockito.when(plugin.getSettings()).thenReturn(settings);
|
Mockito.when(plugin.getSettings()).thenReturn(settings);
|
||||||
@ -124,16 +124,20 @@ public class ExperiencePickupListenerTest {
|
|||||||
when(location.getBlockX()).thenReturn(0);
|
when(location.getBlockX()).thenReturn(0);
|
||||||
when(location.getBlockY()).thenReturn(0);
|
when(location.getBlockY()).thenReturn(0);
|
||||||
when(location.getBlockZ()).thenReturn(0);
|
when(location.getBlockZ()).thenReturn(0);
|
||||||
|
|
||||||
// Set up as valid
|
// Set up as valid
|
||||||
entity = mock(ExperienceOrb.class);
|
entity = mock(ExperienceOrb.class);
|
||||||
targetEntity = mock(Player.class);
|
targetEntity = mock(Player.class);
|
||||||
when(targetEntity.getLocation()).thenReturn(location);
|
when(targetEntity.getLocation()).thenReturn(location);
|
||||||
when(entity.getLocation()).thenReturn(location);
|
when(entity.getLocation()).thenReturn(location);
|
||||||
|
|
||||||
TargetReason reason = TargetReason.CLOSEST_PLAYER;
|
TargetReason reason = TargetReason.CLOSEST_PLAYER;
|
||||||
e = new EntityTargetLivingEntityEvent(entity, targetEntity, reason);
|
e = new EntityTargetLivingEntityEvent(entity, targetEntity, reason);
|
||||||
epl = new ExperiencePickupListener();
|
epl = new ExperiencePickupListener();
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,17 +151,17 @@ public class ExperiencePickupListenerTest {
|
|||||||
assertNull(e.getTarget());
|
assertNull(e.getTarget());
|
||||||
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq("protection.protected"));
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq("protection.protected"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.ExperiencePickupListener#onExperienceOrbTargetPlayer(org.bukkit.event.entity.EntityTargetLivingEntityEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.flags.ExperiencePickupListener#onExperienceOrbTargetPlayer(org.bukkit.event.entity.EntityTargetLivingEntityEvent)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnExperienceOrbTargetPlayerAllowed() {
|
public void testOnExperienceOrbTargetPlayerAllowed() {
|
||||||
epl.onExperienceOrbTargetPlayer(e);
|
epl.onExperienceOrbTargetPlayer(e);
|
||||||
assertNotNull(e.getTarget());
|
assertNotNull(e.getTarget());
|
||||||
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.ExperiencePickupListener#onExperienceOrbTargetPlayer(org.bukkit.event.entity.EntityTargetLivingEntityEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.flags.ExperiencePickupListener#onExperienceOrbTargetPlayer(org.bukkit.event.entity.EntityTargetLivingEntityEvent)}.
|
||||||
*/
|
*/
|
||||||
@ -168,7 +172,7 @@ public class ExperiencePickupListenerTest {
|
|||||||
assertNotNull(e.getTarget());
|
assertNotNull(e.getTarget());
|
||||||
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.ExperiencePickupListener#onExperienceOrbTargetPlayer(org.bukkit.event.entity.EntityTargetLivingEntityEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.flags.ExperiencePickupListener#onExperienceOrbTargetPlayer(org.bukkit.event.entity.EntityTargetLivingEntityEvent)}.
|
||||||
*/
|
*/
|
||||||
|
@ -149,6 +149,9 @@ public class HurtingListenerTest {
|
|||||||
notifier = mock(Notifier.class);
|
notifier = mock(Notifier.class);
|
||||||
when(plugin.getNotifier()).thenReturn(notifier);
|
when(plugin.getNotifier()).thenReturn(notifier);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,20 +69,20 @@ public class LockAndBanListenerTest {
|
|||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
|
||||||
// World
|
// World
|
||||||
world = mock(World.class);
|
world = mock(World.class);
|
||||||
|
|
||||||
// Island world manager
|
// Island world manager
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
|
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
|
||||||
|
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
Settings s = mock(Settings.class);
|
Settings s = mock(Settings.class);
|
||||||
when(plugin.getSettings()).thenReturn(s);
|
when(plugin.getSettings()).thenReturn(s);
|
||||||
@ -117,12 +117,12 @@ public class LockAndBanListenerTest {
|
|||||||
sch = mock(BukkitScheduler.class);
|
sch = mock(BukkitScheduler.class);
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||||
|
|
||||||
// Locales
|
// Locales
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||||
|
|
||||||
// Notifier
|
// Notifier
|
||||||
notifier = mock(Notifier.class);
|
notifier = mock(Notifier.class);
|
||||||
when(plugin.getNotifier()).thenReturn(notifier);
|
when(plugin.getNotifier()).thenReturn(notifier);
|
||||||
@ -142,35 +142,39 @@ public class LockAndBanListenerTest {
|
|||||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||||
|
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||||
|
|
||||||
// Create the listener object
|
// Create the listener object
|
||||||
listener = new LockAndBanListener();
|
listener = new LockAndBanListener();
|
||||||
|
|
||||||
// Common from to's
|
// Common from to's
|
||||||
outside = mock(Location.class);
|
outside = mock(Location.class);
|
||||||
when(outside.getWorld()).thenReturn(world);
|
when(outside.getWorld()).thenReturn(world);
|
||||||
when(outside.getBlockX()).thenReturn(X + PROTECTION_RANGE + 1);
|
when(outside.getBlockX()).thenReturn(X + PROTECTION_RANGE + 1);
|
||||||
when(outside.getBlockY()).thenReturn(Y);
|
when(outside.getBlockY()).thenReturn(Y);
|
||||||
when(outside.getBlockZ()).thenReturn(Z);
|
when(outside.getBlockZ()).thenReturn(Z);
|
||||||
|
|
||||||
inside = mock(Location.class);
|
inside = mock(Location.class);
|
||||||
when(inside.getWorld()).thenReturn(world);
|
when(inside.getWorld()).thenReturn(world);
|
||||||
when(inside.getBlockX()).thenReturn(X + PROTECTION_RANGE - 1);
|
when(inside.getBlockX()).thenReturn(X + PROTECTION_RANGE - 1);
|
||||||
when(inside.getBlockY()).thenReturn(Y);
|
when(inside.getBlockY()).thenReturn(Y);
|
||||||
when(inside.getBlockZ()).thenReturn(Z);
|
when(inside.getBlockZ()).thenReturn(Z);
|
||||||
|
|
||||||
inside2 = mock(Location.class);
|
inside2 = mock(Location.class);
|
||||||
when(inside.getWorld()).thenReturn(world);
|
when(inside.getWorld()).thenReturn(world);
|
||||||
when(inside.getBlockX()).thenReturn(X + PROTECTION_RANGE - 2);
|
when(inside.getBlockX()).thenReturn(X + PROTECTION_RANGE - 2);
|
||||||
when(inside.getBlockY()).thenReturn(Y);
|
when(inside.getBlockY()).thenReturn(Y);
|
||||||
when(inside.getBlockZ()).thenReturn(Z);
|
when(inside.getBlockZ()).thenReturn(Z);
|
||||||
|
|
||||||
Optional<Island> opIsland = Optional.ofNullable(island);
|
Optional<Island> opIsland = Optional.ofNullable(island);
|
||||||
when(im.getProtectedIslandAt(Mockito.eq(inside))).thenReturn(opIsland);
|
when(im.getProtectedIslandAt(Mockito.eq(inside))).thenReturn(opIsland);
|
||||||
when(im.getProtectedIslandAt(Mockito.eq(inside2))).thenReturn(opIsland);
|
when(im.getProtectedIslandAt(Mockito.eq(inside2))).thenReturn(opIsland);
|
||||||
when(im.getProtectedIslandAt(Mockito.eq(outside))).thenReturn(Optional.empty());
|
when(im.getProtectedIslandAt(Mockito.eq(outside))).thenReturn(Optional.empty());
|
||||||
}
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTeleportToNotBannedIsland() {
|
public void testTeleportToNotBannedIsland() {
|
||||||
// Setup location outside island, one inside banned island
|
// Setup location outside island, one inside banned island
|
||||||
@ -186,7 +190,7 @@ public class LockAndBanListenerTest {
|
|||||||
// User should see no message from this class
|
// User should see no message from this class
|
||||||
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.any());
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTeleportToBannedIsland() {
|
public void testTeleportToBannedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -195,7 +199,7 @@ public class LockAndBanListenerTest {
|
|||||||
|
|
||||||
// Add player to the ban list
|
// Add player to the ban list
|
||||||
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
// Simulate a teleport into an island
|
// Simulate a teleport into an island
|
||||||
PlayerTeleportEvent e = new PlayerTeleportEvent(player, outside, inside);
|
PlayerTeleportEvent e = new PlayerTeleportEvent(player, outside, inside);
|
||||||
// Pass to event listener
|
// Pass to event listener
|
||||||
@ -215,15 +219,15 @@ public class LockAndBanListenerTest {
|
|||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player on the island
|
// Place the player on the island
|
||||||
when(player.getLocation()).thenReturn(inside);
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
// Add player to the ban list
|
// Add player to the ban list
|
||||||
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
// Log them in
|
// Log them in
|
||||||
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
||||||
// User should see a message
|
// User should see a message
|
||||||
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
// User should be teleported somewhere
|
// User should be teleported somewhere
|
||||||
Mockito.verify(im).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
// Call teleport event
|
// Call teleport event
|
||||||
PlayerTeleportEvent e = new PlayerTeleportEvent(player, inside, outside);
|
PlayerTeleportEvent e = new PlayerTeleportEvent(player, inside, outside);
|
||||||
@ -232,7 +236,7 @@ public class LockAndBanListenerTest {
|
|||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVerticalMoveOnly() {
|
public void testVerticalMoveOnly() {
|
||||||
// Move vertically only
|
// Move vertically only
|
||||||
@ -252,7 +256,7 @@ public class LockAndBanListenerTest {
|
|||||||
// Confirm no check is done on the island
|
// Confirm no check is done on the island
|
||||||
Mockito.verify(im, Mockito.never()).getProtectedIslandAt(Mockito.any());
|
Mockito.verify(im, Mockito.never()).getProtectedIslandAt(Mockito.any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVerticalVehicleMoveOnly() {
|
public void testVerticalVehicleMoveOnly() {
|
||||||
// Move vertically only
|
// Move vertically only
|
||||||
@ -278,7 +282,7 @@ public class LockAndBanListenerTest {
|
|||||||
// Confirm no check is done on the island
|
// Confirm no check is done on the island
|
||||||
Mockito.verify(im, Mockito.never()).getProtectedIslandAt(Mockito.any());
|
Mockito.verify(im, Mockito.never()).getProtectedIslandAt(Mockito.any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveIntoBannedIsland() {
|
public void testPlayerMoveIntoBannedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -288,7 +292,7 @@ public class LockAndBanListenerTest {
|
|||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player just outside island
|
// Place the player just outside island
|
||||||
when(player.getLocation()).thenReturn(outside);
|
when(player.getLocation()).thenReturn(outside);
|
||||||
|
|
||||||
// Add player to the ban list
|
// Add player to the ban list
|
||||||
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
@ -301,7 +305,7 @@ public class LockAndBanListenerTest {
|
|||||||
// User should NOT be teleported somewhere
|
// User should NOT be teleported somewhere
|
||||||
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveInsideBannedIsland() {
|
public void testPlayerMoveInsideBannedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -311,9 +315,9 @@ public class LockAndBanListenerTest {
|
|||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player inside island
|
// Place the player inside island
|
||||||
when(player.getLocation()).thenReturn(inside);
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
// Add player to the ban list
|
// Add player to the ban list
|
||||||
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Move player
|
// Move player
|
||||||
PlayerMoveEvent e = new PlayerMoveEvent(player, inside, inside2);
|
PlayerMoveEvent e = new PlayerMoveEvent(player, inside, inside2);
|
||||||
listener.onPlayerMove(e);
|
listener.onPlayerMove(e);
|
||||||
@ -329,7 +333,7 @@ public class LockAndBanListenerTest {
|
|||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(ev.isCancelled());
|
assertFalse(ev.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVehicleMoveIntoBannedIsland() {
|
public void testVehicleMoveIntoBannedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -337,13 +341,13 @@ public class LockAndBanListenerTest {
|
|||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
// Give player an island
|
// Give player an island
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
// Add player to the ban list
|
// Add player to the ban list
|
||||||
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
// Add the user to the ban list
|
// Add the user to the ban list
|
||||||
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
// Create vehicle and put two players in it. One is banned, the other is not
|
// Create vehicle and put two players in it. One is banned, the other is not
|
||||||
Vehicle vehicle = mock(Vehicle.class);
|
Vehicle vehicle = mock(Vehicle.class);
|
||||||
Player player2 = mock(Player.class);
|
Player player2 = mock(Player.class);
|
||||||
@ -366,12 +370,12 @@ public class LockAndBanListenerTest {
|
|||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(ev.isCancelled());
|
assertFalse(ev.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Island lock tests
|
* Island lock tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTeleportToLockedIsland() {
|
public void testTeleportToLockedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -388,7 +392,7 @@ public class LockAndBanListenerTest {
|
|||||||
// Player should see a message
|
// Player should see a message
|
||||||
Mockito.verify(notifier).notify(Mockito.any(), Mockito.any());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTeleportToLockedIslandAsMember() {
|
public void testTeleportToLockedIslandAsMember() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -413,15 +417,15 @@ public class LockAndBanListenerTest {
|
|||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player on the island
|
// Place the player on the island
|
||||||
when(player.getLocation()).thenReturn(inside);
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
// Lock island for player
|
// Lock island for player
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
// Log them in
|
// Log them in
|
||||||
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
||||||
// User should see a message
|
// User should see a message
|
||||||
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
// User should be teleported somewhere
|
// User should be teleported somewhere
|
||||||
Mockito.verify(im).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
// Call teleport event
|
// Call teleport event
|
||||||
PlayerTeleportEvent e = new PlayerTeleportEvent(player, inside, outside);
|
PlayerTeleportEvent e = new PlayerTeleportEvent(player, inside, outside);
|
||||||
@ -430,54 +434,54 @@ public class LockAndBanListenerTest {
|
|||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoginToLockedIslandAsOp() {
|
public void testLoginToLockedIslandAsOp() {
|
||||||
// Make player
|
// Make player
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
when(player.isOp()).thenReturn(true);
|
when(player.isOp()).thenReturn(true);
|
||||||
|
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
// Give player an island
|
// Give player an island
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player on the island
|
// Place the player on the island
|
||||||
when(player.getLocation()).thenReturn(inside);
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
// Lock island for player
|
// Lock island for player
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
// Log them in
|
// Log them in
|
||||||
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
||||||
// User should not see a message
|
// User should not see a message
|
||||||
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
||||||
// User should not be teleported somewhere
|
// User should not be teleported somewhere
|
||||||
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoginToLockedIslandWithBypassPerm() {
|
public void testLoginToLockedIslandWithBypassPerm() {
|
||||||
// Make player
|
// Make player
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
when(player.isOp()).thenReturn(false);
|
when(player.isOp()).thenReturn(false);
|
||||||
when(player.hasPermission(Mockito.anyString())).thenReturn(true);
|
when(player.hasPermission(Mockito.anyString())).thenReturn(true);
|
||||||
|
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
// Give player an island
|
// Give player an island
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player on the island
|
// Place the player on the island
|
||||||
when(player.getLocation()).thenReturn(inside);
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
// Lock island for player
|
// Lock island for player
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
// Log them in
|
// Log them in
|
||||||
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
||||||
// User should not see a message
|
// User should not see a message
|
||||||
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
||||||
// User should not be teleported somewhere
|
// User should not be teleported somewhere
|
||||||
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoginToLockedIslandAsMember() {
|
public void testLoginToLockedIslandAsMember() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -491,10 +495,10 @@ public class LockAndBanListenerTest {
|
|||||||
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
||||||
// User should not see a message
|
// User should not see a message
|
||||||
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
||||||
// User should not be teleported somewhere
|
// User should not be teleported somewhere
|
||||||
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveIntoLockedIsland() {
|
public void testPlayerMoveIntoLockedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -504,7 +508,7 @@ public class LockAndBanListenerTest {
|
|||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player just outside island
|
// Place the player just outside island
|
||||||
when(player.getLocation()).thenReturn(outside);
|
when(player.getLocation()).thenReturn(outside);
|
||||||
|
|
||||||
// Lock island for player
|
// Lock island for player
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
@ -517,19 +521,19 @@ public class LockAndBanListenerTest {
|
|||||||
// User should NOT be teleported somewhere
|
// User should NOT be teleported somewhere
|
||||||
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveIntoLockedIslandAsOp() {
|
public void testPlayerMoveIntoLockedIslandAsOp() {
|
||||||
// Make player
|
// Make player
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
when(player.isOp()).thenReturn(true);
|
when(player.isOp()).thenReturn(true);
|
||||||
|
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
// Give player an island
|
// Give player an island
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player just outside island
|
// Place the player just outside island
|
||||||
when(player.getLocation()).thenReturn(outside);
|
when(player.getLocation()).thenReturn(outside);
|
||||||
|
|
||||||
// Lock island for player
|
// Lock island for player
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
@ -538,20 +542,20 @@ public class LockAndBanListenerTest {
|
|||||||
listener.onPlayerMove(e);
|
listener.onPlayerMove(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveIntoLockedIslandWithBypass() {
|
public void testPlayerMoveIntoLockedIslandWithBypass() {
|
||||||
// Make player
|
// Make player
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
when(player.isOp()).thenReturn(false);
|
when(player.isOp()).thenReturn(false);
|
||||||
when(player.hasPermission(Mockito.anyString())).thenReturn(true);
|
when(player.hasPermission(Mockito.anyString())).thenReturn(true);
|
||||||
|
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
// Give player an island
|
// Give player an island
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player just outside island
|
// Place the player just outside island
|
||||||
when(player.getLocation()).thenReturn(outside);
|
when(player.getLocation()).thenReturn(outside);
|
||||||
|
|
||||||
// Lock island for player
|
// Lock island for player
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
@ -560,8 +564,8 @@ public class LockAndBanListenerTest {
|
|||||||
listener.onPlayerMove(e);
|
listener.onPlayerMove(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveIntoLockedIslandAsMember() {
|
public void testPlayerMoveIntoLockedIslandAsMember() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -581,7 +585,7 @@ public class LockAndBanListenerTest {
|
|||||||
// User should NOT be teleported somewhere
|
// User should NOT be teleported somewhere
|
||||||
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveInsideLockedIsland() {
|
public void testPlayerMoveInsideLockedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -591,7 +595,7 @@ public class LockAndBanListenerTest {
|
|||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player inside island
|
// Place the player inside island
|
||||||
when(player.getLocation()).thenReturn(inside);
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
// Lock island for player
|
// Lock island for player
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
@ -610,7 +614,7 @@ public class LockAndBanListenerTest {
|
|||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(ev.isCancelled());
|
assertFalse(ev.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveInsideLockedIslandAsOp() {
|
public void testPlayerMoveInsideLockedIslandAsOp() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -621,7 +625,7 @@ public class LockAndBanListenerTest {
|
|||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player inside island
|
// Place the player inside island
|
||||||
when(player.getLocation()).thenReturn(inside);
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
// Lock island for player
|
// Lock island for player
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
@ -630,7 +634,7 @@ public class LockAndBanListenerTest {
|
|||||||
listener.onPlayerMove(e);
|
listener.onPlayerMove(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveInsideLockedIslandWithBypass() {
|
public void testPlayerMoveInsideLockedIslandWithBypass() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -642,7 +646,7 @@ public class LockAndBanListenerTest {
|
|||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Place the player inside island
|
// Place the player inside island
|
||||||
when(player.getLocation()).thenReturn(inside);
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
// Lock island for player
|
// Lock island for player
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
@ -651,8 +655,8 @@ public class LockAndBanListenerTest {
|
|||||||
listener.onPlayerMove(e);
|
listener.onPlayerMove(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlayerMoveInsideLockedIslandAsMember() {
|
public void testPlayerMoveInsideLockedIslandAsMember() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -671,7 +675,7 @@ public class LockAndBanListenerTest {
|
|||||||
// User should not be teleported somewhere
|
// User should not be teleported somewhere
|
||||||
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.any(), Mockito.eq(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVehicleMoveIntoLockedIsland() {
|
public void testVehicleMoveIntoLockedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
@ -682,10 +686,10 @@ public class LockAndBanListenerTest {
|
|||||||
Player player2 = mock(Player.class);
|
Player player2 = mock(Player.class);
|
||||||
UUID uuid2 = UUID.randomUUID();
|
UUID uuid2 = UUID.randomUUID();
|
||||||
when(player2.getUniqueId()).thenReturn(uuid2);
|
when(player2.getUniqueId()).thenReturn(uuid2);
|
||||||
|
|
||||||
// Player 1 is not a member, player 2 is an island member
|
// Player 1 is not a member, player 2 is an island member
|
||||||
when(island.isAllowed(Mockito.any(User.class), Mockito.any())).thenAnswer((Answer<Boolean>) invocation -> invocation.getArgumentAt(0, User.class).getUniqueId().equals(uuid2));
|
when(island.isAllowed(Mockito.any(User.class), Mockito.any())).thenAnswer((Answer<Boolean>) invocation -> invocation.getArgumentAt(0, User.class).getUniqueId().equals(uuid2));
|
||||||
|
|
||||||
// Create vehicle and put two players in it. One is a member, the other is not
|
// Create vehicle and put two players in it. One is a member, the other is not
|
||||||
Vehicle vehicle = mock(Vehicle.class);
|
Vehicle vehicle = mock(Vehicle.class);
|
||||||
List<Entity> passengers = new ArrayList<>();
|
List<Entity> passengers = new ArrayList<>();
|
||||||
@ -707,5 +711,5 @@ public class LockAndBanListenerTest {
|
|||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(ev.isCancelled());
|
assertFalse(ev.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -142,6 +143,10 @@ public class ObsidianScoopingListenerTest {
|
|||||||
Map<String, Boolean> map = new HashMap<>();
|
Map<String, Boolean> map = new HashMap<>();
|
||||||
map.put("OBSIDIAN_SCOOPING", true);
|
map.put("OBSIDIAN_SCOOPING", true);
|
||||||
when(ws.getWorldFlags()).thenReturn(map);
|
when(ws.getWorldFlags()).thenReturn(map);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -193,6 +193,10 @@ public class PVPListenerTest {
|
|||||||
// Notifier
|
// Notifier
|
||||||
notifier = mock(Notifier.class);
|
notifier = mock(Notifier.class);
|
||||||
when(plugin.getNotifier()).thenReturn(notifier);
|
when(plugin.getNotifier()).thenReturn(notifier);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void wrongWorld() {
|
private void wrongWorld() {
|
||||||
|
@ -99,7 +99,6 @@ public class PhysicalInteractionListenerTest {
|
|||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
//Bukkit.setServer(server);
|
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
@ -182,6 +181,10 @@ public class PhysicalInteractionListenerTest {
|
|||||||
item = mock(ItemStack.class);
|
item = mock(ItemStack.class);
|
||||||
clickedBlock = mock(Block.class);
|
clickedBlock = mock(Block.class);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -91,7 +91,6 @@ public class TNTListenerTest {
|
|||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
//Bukkit.setServer(server);
|
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
@ -164,6 +163,10 @@ public class TNTListenerTest {
|
|||||||
|
|
||||||
PowerMockito.mockStatic(Util.class);
|
PowerMockito.mockStatic(Util.class);
|
||||||
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
|
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -182,6 +182,10 @@ public class IslandsManagerTest {
|
|||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
pim = mock(PluginManager.class);
|
pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(server.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
package world.bentobox.bentobox.util.teleport;
|
package world.bentobox.bentobox.util.teleport;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -7,20 +15,17 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
import world.bentobox.bentobox.managers.LocalesManager;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest(SafeSpotTeleport.Builder.class)
|
@PrepareForTest(SafeSpotTeleport.Builder.class)
|
||||||
public class SafeSpotTeleportBuilderTest {
|
public class SafeSpotTeleportBuilderTest {
|
||||||
@ -46,6 +51,11 @@ public class SafeSpotTeleportBuilderTest {
|
|||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||||
|
// Addon
|
||||||
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -95,6 +95,10 @@ public class SafeSpotTeleportTest {
|
|||||||
sch = mock(BukkitScheduler.class);
|
sch = mock(BukkitScheduler.class);
|
||||||
when(server.getScheduler()).thenReturn(sch);
|
when(server.getScheduler()).thenReturn(sch);
|
||||||
|
|
||||||
|
// Addon
|
||||||
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user