From 3f83a89215f37eb8d2997283d5ffc0e50cb00f69 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sat, 11 May 2019 16:11:57 +0200 Subject: [PATCH] Added placeholders replacement in BentoBox's own messages It is now possible to use external placeholders into BentoBox's messages. --- .../bentobox/bentobox/api/user/User.java | 22 +++++---- .../bentobox/hooks/PlaceholderAPIHook.java | 14 ++++++ .../managers/PlaceholdersManager.java | 16 ++++++ .../island/IslandExpelCommandTest.java | 35 +++++++------ .../team/IslandTeamKickCommandTest.java | 6 +++ .../bentobox/bentobox/api/user/UserTest.java | 39 ++++++++------- .../listeners/BannedVisitorCommandsTest.java | 35 +++++++------ .../protection/BreakBlocksListenerTest.java | 35 +++++++------ .../protection/BreedingListenerTest.java | 35 +++++++------ .../flags/protection/BucketListenerTest.java | 35 +++++++------ .../flags/protection/EggListenerTest.java | 33 +++++++------ .../ExperiencePickupListenerTest.java | 31 +++++++----- .../flags/protection/HurtingListenerTest.java | 27 +++++----- .../protection/InventoryListenerTest.java | 37 ++++++++------ .../protection/LockAndBanListenerTest.java | 31 +++++++----- .../PhysicalInteractionListenerTest.java | 35 +++++++------ .../protection/PlaceBlocksListenerTest.java | 35 +++++++------ .../flags/protection/TNTListenerTest.java | 37 ++++++++------ .../protection/ThrowingListenerTest.java | 35 +++++++------ .../flags/settings/PVPListenerTest.java | 49 ++++++++++--------- .../worldsettings/EnderChestListenerTest.java | 32 +++++++----- .../worldsettings/EnterExitListenerTest.java | 25 ++++++---- .../ObsidianScoopingListenerTest.java | 31 ++++++------ .../bentobox/managers/IslandsManagerTest.java | 48 +++++++++--------- 24 files changed, 448 insertions(+), 310 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/user/User.java b/src/main/java/world/bentobox/bentobox/api/user/User.java index f0f60a699..2e062a1c1 100644 --- a/src/main/java/world/bentobox/bentobox/api/user/User.java +++ b/src/main/java/world/bentobox/bentobox/api/user/User.java @@ -1,13 +1,5 @@ package world.bentobox.bentobox.api.user; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -23,11 +15,18 @@ import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.util.Vector; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.events.OfflineMessageEvent; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; + /** * Combines {@link Player}, {@link OfflinePlayer} and {@link CommandSender} to provide convenience methods related to * localization and generic interactions. @@ -348,6 +347,11 @@ public class User { } } + // Then replace Placeholders, this will only work if this is a player + if (player != null) { + translation = plugin.getPlaceholdersManager().replacePlaceholders(player, translation); + } + return ChatColor.translateAlternateColorCodes('&', translation); } diff --git a/src/main/java/world/bentobox/bentobox/hooks/PlaceholderAPIHook.java b/src/main/java/world/bentobox/bentobox/hooks/PlaceholderAPIHook.java index 0f80881d1..cc55a910d 100644 --- a/src/main/java/world/bentobox/bentobox/hooks/PlaceholderAPIHook.java +++ b/src/main/java/world/bentobox/bentobox/hooks/PlaceholderAPIHook.java @@ -1,6 +1,8 @@ package world.bentobox.bentobox.hooks; +import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.eclipse.jdt.annotation.NonNull; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.addons.Addon; @@ -103,4 +105,16 @@ public class PlaceholderAPIHook extends Hook { public boolean isPlaceholder(@NonNull Addon addon, @NonNull String placeholder) { return addonsExpansions.containsKey(addon) && addonsExpansions.get(addon).isPlaceholder(placeholder); } + + /** + * Replaces the placeholders in this String and returns it. + * @param player the Player to get the placeholders for. + * @param string the String to replace the placeholders in. + * @return the String with placeholders replaced, or the identical String if no placeholders were available. + * @since 1.5.0 + */ + @NonNull + public String replacePlaceholders(@NonNull Player player, @NonNull String string) { + return PlaceholderAPI.setPlaceholders(player, string); + } } diff --git a/src/main/java/world/bentobox/bentobox/managers/PlaceholdersManager.java b/src/main/java/world/bentobox/bentobox/managers/PlaceholdersManager.java index 81f80b450..31304185f 100644 --- a/src/main/java/world/bentobox/bentobox/managers/PlaceholdersManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/PlaceholdersManager.java @@ -1,5 +1,6 @@ package world.bentobox.bentobox.managers; +import org.bukkit.entity.Player; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import world.bentobox.bentobox.BentoBox; @@ -121,4 +122,19 @@ public class PlaceholdersManager { public boolean isPlaceholder(@NonNull Addon addon, @NonNull String placeholder) { return getPlaceholderAPIHook().map(h -> h.isPlaceholder(addon, placeholder)).orElse(false); } + + /** + * Replaces the placeholders in this String and returns it. + * @param player the Player to get the placeholders for. + * @param string the String to replace the placeholders in. + * @return the String with placeholders replaced, or the identical String if no placeholders were available. + * @since 1.5.0 + */ + public String replacePlaceholders(@NonNull Player player, @NonNull String string) { + if (getPlaceholderAPIHook().isPresent()) { + string = getPlaceholderAPIHook().get().replacePlaceholders(player, string); + } + + return string; + } } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java index a8bb5ba2c..bd6a98846 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java @@ -3,18 +3,6 @@ */ package world.bentobox.bentobox.api.commands.island; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Optional; -import java.util.UUID; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -33,7 +21,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.addons.Addon; @@ -46,9 +33,22 @@ import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.RanksManager; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Optional; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -140,8 +140,15 @@ public class IslandExpelCommandTest { when(island.getWorld()).thenReturn(mock(World.class)); // Locales - when(lm.get(Mockito.any(User.class), Mockito.anyString())).thenAnswer((Answer) invocation -> invocation.getArgumentAt(1, String.class)); + Answer answer = invocation -> invocation.getArgumentAt(1, String.class); + when(lm.get(Mockito.any(User.class), Mockito.anyString())).thenAnswer(answer); when(plugin.getLocalesManager()).thenReturn(lm); + + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(Mockito.any(), Mockito.any())).thenAnswer(answer); + // Class iec = new IslandExpelCommand(ic); } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java index 17210c00f..fc2511e8d 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java @@ -24,6 +24,7 @@ import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlayersManager; import java.util.Collections; @@ -119,6 +120,11 @@ public class IslandTeamKickCommandTest { when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); when(plugin.getLocalesManager()).thenReturn(lm); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(Mockito.any(), Mockito.any())).thenReturn("mock translation"); + // IWM friendly name iwm = mock(IslandWorldManager.class); when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); diff --git a/src/test/java/world/bentobox/bentobox/api/user/UserTest.java b/src/test/java/world/bentobox/bentobox/api/user/UserTest.java index 021e8f228..0896f92e5 100644 --- a/src/test/java/world/bentobox/bentobox/api/user/UserTest.java +++ b/src/test/java/world/bentobox/bentobox/api/user/UserTest.java @@ -1,21 +1,5 @@ package world.bentobox.bentobox.api.user; -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; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashSet; -import java.util.Locale; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -37,15 +21,31 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; 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.PlaceholdersManager; import world.bentobox.bentobox.managers.PlayersManager; +import java.util.HashSet; +import java.util.Locale; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.logging.Logger; + +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; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + @RunWith(PowerMockRunner.class) @PrepareForTest({ BentoBox.class, Bukkit.class }) @@ -101,6 +101,11 @@ public class UserTest { when(lm.get(any(), any())).thenReturn(TEST_TRANSLATION); when(lm.get(any())).thenReturn(TEST_TRANSLATION); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn(TEST_TRANSLATION); + } @After diff --git a/src/test/java/world/bentobox/bentobox/listeners/BannedVisitorCommandsTest.java b/src/test/java/world/bentobox/bentobox/listeners/BannedVisitorCommandsTest.java index eec07e99e..28b0fb69c 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/BannedVisitorCommandsTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/BannedVisitorCommandsTest.java @@ -1,19 +1,5 @@ package world.bentobox.bentobox.listeners; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -28,15 +14,29 @@ import org.mockito.stubbing.Answer; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.user.Notifier; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + @RunWith(PowerMockRunner.class) @PrepareForTest({BentoBox.class, Util.class, Bukkit.class }) public class BannedVisitorCommandsTest { @@ -89,6 +89,11 @@ public class BannedVisitorCommandsTest { when(plugin.getLocalesManager()).thenReturn(lm); when(lm.get(any(), any())).thenReturn("mock translation"); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation"); + // Notifier Notifier notifier = mock(Notifier.class); when(plugin.getNotifier()).thenReturn(notifier); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java index 3720cc9ba..f0c499659 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java @@ -1,19 +1,5 @@ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -53,7 +39,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -65,8 +50,23 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -144,6 +144,11 @@ public class BreakBlocksListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // World Settings WorldSettings ws = mock(WorldSettings.class); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListenerTest.java index dc9c08eb4..8b444ab60 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListenerTest.java @@ -3,20 +3,6 @@ */ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -45,7 +31,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -57,9 +42,24 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.util.Util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -158,6 +158,11 @@ public class BreedingListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // Player name PlayersManager pm = mock(PlayersManager.class); when(pm.getName(Mockito.any())).thenReturn("tastybento"); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java index 751b04c29..e11a9f430 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java @@ -1,19 +1,5 @@ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -41,7 +27,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -53,8 +38,23 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -131,6 +131,11 @@ public class BucketListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // World Settings WorldSettings ws = mock(WorldSettings.class); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EggListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EggListenerTest.java index ba1c0e826..be21b9631 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EggListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EggListenerTest.java @@ -1,18 +1,5 @@ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -34,7 +21,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -46,8 +32,22 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -124,6 +124,11 @@ public class EggListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // World Settings WorldSettings ws = mock(WorldSettings.class); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ExperiencePickupListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ExperiencePickupListenerTest.java index 060a6ddb0..5aff24e1d 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ExperiencePickupListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ExperiencePickupListenerTest.java @@ -3,18 +3,6 @@ */ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertNotNull; -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.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -35,7 +23,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -45,8 +32,21 @@ import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * Tests the listener * @author tastybento @@ -97,6 +97,11 @@ public class ExperiencePickupListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // World Settings WorldSettings ws = mock(WorldSettings.class); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListenerTest.java index f10822c2b..bfbb670e8 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListenerTest.java @@ -3,16 +3,6 @@ */ package world.bentobox.bentobox.listeners.flags.protection; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -39,7 +29,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -51,8 +40,19 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.logging.Logger; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -145,6 +145,11 @@ public class HurtingListenerTest { Answer answer = invocation -> invocation.getArgumentAt(1, String.class); when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // Notifier notifier = mock(Notifier.class); when(plugin.getNotifier()).thenReturn(notifier); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListenerTest.java index 16c90763c..dddf62ebb 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListenerTest.java @@ -1,20 +1,5 @@ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -50,7 +35,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -62,8 +46,24 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -143,6 +143,11 @@ public class InventoryListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // World Settings WorldSettings ws = mock(WorldSettings.class); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListenerTest.java index 7183a035b..cb0406da9 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListenerTest.java @@ -1,17 +1,5 @@ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -32,7 +20,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.user.Notifier; @@ -42,8 +29,21 @@ import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlayersManager; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + @RunWith(PowerMockRunner.class) @PrepareForTest({Bukkit.class, BentoBox.class, User.class }) public class LockAndBanListenerTest { @@ -123,6 +123,11 @@ public class LockAndBanListenerTest { when(plugin.getLocalesManager()).thenReturn(lm); when(lm.get(any(), any())).thenReturn("mock translation"); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation"); + // Notifier notifier = mock(Notifier.class); when(plugin.getNotifier()).thenReturn(notifier); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PhysicalInteractionListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PhysicalInteractionListenerTest.java index 8c8757635..7b5bfa8ea 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PhysicalInteractionListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PhysicalInteractionListenerTest.java @@ -1,19 +1,5 @@ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -46,7 +32,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -58,9 +43,24 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.util.Util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -142,6 +142,11 @@ public class PhysicalInteractionListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // Player name PlayersManager pm = mock(PlayersManager.class); when(pm.getName(Mockito.any())).thenReturn("tastybento"); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java index a3f951104..5c01daae3 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java @@ -3,20 +3,6 @@ */ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -49,7 +35,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -61,8 +46,23 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -138,6 +138,11 @@ public class PlaceBlocksListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // World Settings WorldSettings ws = mock(WorldSettings.class); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/TNTListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/TNTListenerTest.java index 57aa9b04a..a7a63b59d 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/TNTListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/TNTListenerTest.java @@ -1,20 +1,5 @@ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -48,7 +33,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -60,9 +44,25 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.util.Util; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + @RunWith(PowerMockRunner.class) @PrepareForTest( {BentoBox.class, Flags.class, Util.class, Bukkit.class} ) public class TNTListenerTest { @@ -139,6 +139,11 @@ public class TNTListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // Player name PlayersManager pm = mock(PlayersManager.class); when(pm.getName(Mockito.any())).thenReturn("tastybento"); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ThrowingListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ThrowingListenerTest.java index febb4c357..b24c482fd 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ThrowingListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ThrowingListenerTest.java @@ -3,20 +3,6 @@ */ package world.bentobox.bentobox.listeners.flags.protection; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -38,7 +24,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -50,8 +35,23 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** @@ -129,6 +129,11 @@ public class ThrowingListenerTest { Answer answer = invocation -> (String)Arrays.asList(invocation.getArguments()).get(1); when(lm.get(any(), any())).thenAnswer(answer); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); + // World Settings WorldSettings ws = mock(WorldSettings.class); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java index 5109581e9..26b13331a 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java @@ -3,22 +3,9 @@ */ package world.bentobox.bentobox.listeners.flags.settings; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - +import com.google.common.base.Function; +import com.google.common.base.Functions; +import com.google.common.collect.ImmutableMap; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -53,11 +40,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - -import com.google.common.base.Function; -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableMap; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -72,8 +54,25 @@ import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -169,7 +168,13 @@ public class PVPListenerTest { // Locales - this returns the string that was requested for translation LocalesManager lm = mock(LocalesManager.class); when(plugin.getLocalesManager()).thenReturn(lm); - when(lm.get(any(), any())).thenAnswer((Answer) invocation -> invocation.getArgumentAt(1, String.class)); + Answer answer = (Answer) invocation -> invocation.getArgumentAt(1, String.class); + when(lm.get(any(), any())).thenAnswer(answer); + + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); // Create some entities zombie = mock(Zombie.class); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnderChestListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnderChestListenerTest.java index 3a5083bbf..23d6951ca 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnderChestListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnderChestListenerTest.java @@ -1,16 +1,5 @@ package world.bentobox.bentobox.listeners.flags.worldsettings; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -37,7 +26,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -49,8 +37,20 @@ import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.util.Util; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + @RunWith(PowerMockRunner.class) @PrepareForTest({BentoBox.class, Util.class }) public class EnderChestListenerTest { @@ -122,7 +122,13 @@ public class EnderChestListenerTest { // Locales - this returns the string that was requested for translation LocalesManager lm = mock(LocalesManager.class); when(plugin.getLocalesManager()).thenReturn(lm); - when(lm.get(any(), any())).thenAnswer((Answer) invocation -> invocation.getArgumentAt(1, String.class)); + Answer answer = invocation -> invocation.getArgumentAt(1, String.class); + when(lm.get(any(), any())).thenAnswer(answer); + + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); // Notifier notifier = mock(Notifier.class); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java index 7e3c7b25a..32ff9a22b 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java @@ -1,14 +1,5 @@ package world.bentobox.bentobox.listeners.flags.worldsettings; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -25,7 +16,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -36,9 +26,19 @@ import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.util.Util; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -102,6 +102,11 @@ public class EnterExitListenerTest { when(plugin.getLocalesManager()).thenReturn(lm); when(lm.get(any(), any())).thenReturn("mock translation"); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation"); + // Notifier Notifier notifier = mock(Notifier.class); when(plugin.getNotifier()).thenReturn(notifier); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/ObsidianScoopingListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/ObsidianScoopingListenerTest.java index c8882249d..4f1469598 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/ObsidianScoopingListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/ObsidianScoopingListenerTest.java @@ -1,16 +1,5 @@ package world.bentobox.bentobox.listeners.flags.worldsettings; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.logging.Logger; - import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -33,13 +22,24 @@ import org.mockito.Mockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.managers.PlaceholdersManager; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.logging.Logger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; @RunWith(PowerMockRunner.class) @PrepareForTest({BentoBox.class, PlayerEvent.class, PlayerInteractEvent.class}) @@ -134,6 +134,11 @@ public class ObsidianScoopingListenerTest { when(plugin.getLocalesManager()).thenReturn(lm); when(lm.get(any(), any())).thenReturn("mock translation"); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation"); + // World settings Flag WorldSettings ws = mock(WorldSettings.class); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); @@ -267,7 +272,5 @@ public class ObsidianScoopingListenerTest { when(world.getBlockAt(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(airBlock); assertTrue(listener.onPlayerInteract(event)); } - - } } diff --git a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java index 08f3c4b17..4888b1a49 100644 --- a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java @@ -1,24 +1,7 @@ package world.bentobox.bentobox.managers; -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; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; - +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -50,10 +33,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.configuration.WorldSettings; @@ -65,6 +44,25 @@ import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.managers.island.IslandCache; import world.bentobox.bentobox.util.Util; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; + +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; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + @RunWith(PowerMockRunner.class) @PrepareForTest( { Bukkit.class, BentoBox.class, Util.class, Location.class }) public class IslandsManagerTest { @@ -124,6 +122,10 @@ public class IslandsManagerTest { when(plugin.getLocalesManager()).thenReturn(lm); when(lm.get(any(), any())).thenReturn("mock translation"); + // Placeholders + PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class); + when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); + when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation"); // Has team pm = mock(PlayersManager.class);