Allows a space to be placed after a color code in locale files. (#1045)

Space will be stripped if it exists. This makes GitLocalize able to
machine translate much better.

Changes to the English locale file was made. Other languages do not have
to add spaces. Note that adding or removing spaces from files is easy
with regex.

https://github.com/BentoBoxWorld/BentoBox/issues/1044
This commit is contained in:
tastybento 2019-11-30 16:17:38 -08:00 committed by GitHub
parent eab62827cf
commit 032b5c2988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 663 additions and 571 deletions

View File

@ -28,6 +28,7 @@ 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 world.bentobox.bentobox.util.Util;
/**
* Combines {@link Player}, {@link OfflinePlayer} and {@link CommandSender} to provide convenience methods related to
@ -386,7 +387,7 @@ public class User {
translation = plugin.getPlaceholdersManager().replacePlaceholders(player, translation);
}
return ChatColor.translateAlternateColorCodes('&', translation);
return Util.stripSpaceAfterColorCodes(ChatColor.translateAlternateColorCodes('&', translation));
}
/**

View File

@ -13,7 +13,9 @@ import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
@ -518,5 +520,16 @@ public class Util {
return PaperLib.isPaper();
}
/**
* Strips spaces immediately after color codes. Used by {@link User#getTranslation(String, String...)}.
* @param textToStrip - text to strip
* @return text with spaces after color codes removed
* @since 1.9.0
*/
@NonNull
public static String stripSpaceAfterColorCodes(@NonNull String textToStrip) {
Validate.notNull(textToStrip, "Cannot strip null text");
textToStrip = textToStrip.replaceAll("(" + ChatColor.COLOR_CHAR + ".)[\\s]", "$1");
return textToStrip;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,9 @@ package world.bentobox.bentobox.api.commands.island;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -172,6 +172,9 @@ public class IslandGoCommandTest {
// Notifier
when(plugin.getNotifier()).thenReturn(notifier);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Command
igc = new IslandGoCommand(ic);

View File

@ -6,8 +6,11 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -34,7 +37,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -222,7 +224,7 @@ public class UserTest {
@Test
public void testHasPermission() {
when(player.hasPermission(Mockito.anyString())).thenReturn(true);
when(player.hasPermission(anyString())).thenReturn(true);
assertTrue(user.hasPermission(""));
assertTrue(user.hasPermission("perm"));
}
@ -295,7 +297,7 @@ public class UserTest {
when(iwm .getAddon(any())).thenReturn(optionalAddon);
when(lm.get(any(), eq("name.a.reference"))).thenReturn("mockmockmock");
user.sendMessage("a.reference");
verify(player, Mockito.never()).sendMessage(eq(TEST_TRANSLATION));
verify(player, never()).sendMessage(eq(TEST_TRANSLATION));
verify(player).sendMessage(eq("mockmockmock"));
}
@ -304,7 +306,7 @@ public class UserTest {
// Nothing - blank translation
when(lm.get(any(), any())).thenReturn("");
user.sendMessage("a.reference");
verify(player, Mockito.never()).sendMessage(Mockito.anyString());
verify(player, never()).sendMessage(anyString());
}
@Test
@ -316,7 +318,14 @@ public class UserTest {
}
when(lm.get(any(), any())).thenReturn(allColors.toString());
user.sendMessage("a.reference");
verify(player, Mockito.never()).sendMessage(Mockito.anyString());
verify(player, never()).sendMessage(anyString());
}
@Test
public void testSendMessageColorsAndSpaces() {
when(lm.get(any(), any())).thenReturn(ChatColor.COLOR_CHAR + "6 Hello there");
user.sendMessage("a.reference");
verify(player).sendMessage(eq(ChatColor.COLOR_CHAR + "6Hello there"));
}
@Test
@ -331,7 +340,7 @@ public class UserTest {
String raw = ChatColor.RED + "" + ChatColor.BOLD + "test message";
user = User.getInstance((CommandSender)null);
user.sendRawMessage(raw);
verify(player, Mockito.never()).sendMessage(Mockito.anyString());
verify(player, never()).sendMessage(anyString());
}
@Test
@ -355,7 +364,7 @@ public class UserTest {
for (GameMode gm: GameMode.values()) {
user.setGameMode(gm);
}
verify(player, Mockito.times(GameMode.values().length)).setGameMode(any());
verify(player, times(GameMode.values().length)).setGameMode(any());
}
@Test

View File

@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@ -75,13 +76,13 @@ public class StandardSpawnProtectionListenerTest {
private Location location;
@Mock
private Block block;
private StandardSpawnProtectionListener ssp;
@Mock
private BlockState blockState;
@Mock
private Location spawnLocation;
/**
* @throws java.lang.Exception
*/
@ -94,7 +95,7 @@ public class StandardSpawnProtectionListenerTest {
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
when(nether.getEnvironment()).thenReturn(World.Environment.NETHER);
when(end.getEnvironment()).thenReturn(World.Environment.THE_END);
when(world.getSpawnLocation()).thenReturn(spawnLocation);
when(nether.getSpawnLocation()).thenReturn(spawnLocation);
when(end.getSpawnLocation()).thenReturn(spawnLocation);
@ -127,7 +128,10 @@ public class StandardSpawnProtectionListenerTest {
// Block
when(block.getLocation()).thenReturn(location);
// BlockState
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Set up class
ssp = new StandardSpawnProtectionListener(plugin);
}
@ -151,7 +155,7 @@ public class StandardSpawnProtectionListenerTest {
assertTrue(e.isCancelled());
verify(player).sendMessage("protection.spawn-protected");
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
*/
@ -163,7 +167,7 @@ public class StandardSpawnProtectionListenerTest {
assertFalse(e.isCancelled());
verify(player, never()).sendMessage("protection.spawn-protected");
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
*/
@ -175,7 +179,7 @@ public class StandardSpawnProtectionListenerTest {
assertFalse(e.isCancelled());
verify(player, never()).sendMessage("protection.spawn-protected");
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
*/
@ -188,7 +192,7 @@ public class StandardSpawnProtectionListenerTest {
assertFalse(e.isCancelled());
verify(player, never()).sendMessage("protection.spawn-protected");
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
*/
@ -200,7 +204,7 @@ public class StandardSpawnProtectionListenerTest {
assertFalse(e.isCancelled());
verify(player, never()).sendMessage("protection.spawn-protected");
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
*/
@ -226,7 +230,7 @@ public class StandardSpawnProtectionListenerTest {
assertTrue(e.isCancelled());
verify(player).sendMessage("protection.spawn-protected");
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}.
*/
@ -272,7 +276,7 @@ public class StandardSpawnProtectionListenerTest {
assertTrue(e.isCancelled());
verify(player).sendMessage("protection.spawn-protected");
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.StandardSpawnProtectionListener#onBucketEmpty(org.bukkit.event.player.PlayerBucketEmptyEvent)}.
*/

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@ -189,6 +190,9 @@ public class BreakBlocksListenerTest {
when(player.getName()).thenReturn("tastybento");
when(player.getWorld()).thenReturn(world);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Listener
bbl = new BreakBlocksListener();
}

View File

@ -6,6 +6,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -188,6 +189,8 @@ public class BreedingListenerTest {
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Addon
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());

View File

@ -3,7 +3,11 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
@ -35,6 +39,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
@ -64,14 +69,21 @@ import world.bentobox.bentobox.util.Util;
@PrepareForTest( {BentoBox.class, Flags.class, Util.class, Bukkit.class} )
public class BucketListenerTest {
@Mock
private Location location;
@Mock
private BentoBox plugin;
@Mock
private Notifier notifier;
private BucketListener l;
@Mock
private Player player;
@Mock
private World world;
@Mock
private Island island;
@Mock
private IslandWorldManager iwm;
/**
@ -80,11 +92,9 @@ public class BucketListenerTest {
@Before
public void setUp() throws Exception {
// Set up plugin
plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Server server = mock(Server.class);
world = mock(World.class);
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
when(server.getWorld("world")).thenReturn(world);
when(server.getVersion()).thenReturn("BSB_Mocking");
@ -102,7 +112,6 @@ public class BucketListenerTest {
when(itemFactory.getItemMeta(any())).thenReturn(meta);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
location = mock(Location.class);
when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(0);
when(location.getBlockY()).thenReturn(0);
@ -114,7 +123,6 @@ public class BucketListenerTest {
// Worlds
iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm);
@ -153,17 +161,17 @@ public class BucketListenerTest {
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
// Notifier
notifier = mock(Notifier.class);
when(plugin.getNotifier()).thenReturn(notifier);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Addon
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
// Player
player = mock(Player.class);
when(player.getLocation()).thenReturn(location);
when(player.getUniqueId()).thenReturn(UUID.randomUUID());
when(player.getName()).thenReturn("tastybento");
@ -189,7 +197,7 @@ public class BucketListenerTest {
public void testOnBucketEmptyAllowed() {
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getRelative(Mockito.any())).thenReturn(block);
when(block.getRelative(any())).thenReturn(block);
ItemStack item = mock(ItemStack.class);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item);
l.onBucketEmpty(e);
@ -201,15 +209,15 @@ public class BucketListenerTest {
*/
@Test
public void testOnBucketEmptyNotAllowed() {
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
when(island.isAllowed(any(), any())).thenReturn(false);
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getRelative(Mockito.any())).thenReturn(block);
when(block.getRelative(any())).thenReturn(block);
ItemStack item = mock(ItemStack.class);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item);
l.onBucketEmpty(e);
assertTrue(e.isCancelled());
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq("protection.protected"));
verify(notifier).notify(any(), eq("protection.protected"));
}
/**
@ -219,7 +227,7 @@ public class BucketListenerTest {
public void testOnBucketFillAllowed() {
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getRelative(Mockito.any())).thenReturn(block);
when(block.getRelative(any())).thenReturn(block);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item);
@ -247,10 +255,10 @@ public class BucketListenerTest {
*/
@Test
public void testOnBucketFillNotAllowed() {
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
when(island.isAllowed(any(), any())).thenReturn(false);
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getRelative(Mockito.any())).thenReturn(block);
when(block.getRelative(any())).thenReturn(block);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item);
@ -272,7 +280,7 @@ public class BucketListenerTest {
l.onBucketFill(e);
assertTrue(e.isCancelled());
Mockito.verify(notifier, Mockito.times(4)).notify(Mockito.any(), Mockito.eq("protection.protected"));
verify(notifier, times(4)).notify(any(), eq("protection.protected"));
}
/**
@ -324,7 +332,7 @@ public class BucketListenerTest {
*/
@Test
public void testOnTropicalFishScoopingFishWaterBucketNotAllowed() {
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
when(island.isAllowed(any(), any())).thenReturn(false);
TropicalFish fish = mock(TropicalFish.class);
when(fish.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, fish );
@ -336,6 +344,6 @@ public class BucketListenerTest {
l.onTropicalFishScooping(e);
assertTrue(e.isCancelled());
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq("protection.protected"));
verify(notifier).notify(any(), eq("protection.protected"));
}
}

View File

@ -2,8 +2,12 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import java.util.Arrays;
import java.util.HashMap;
@ -28,6 +32,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
@ -57,14 +62,21 @@ import world.bentobox.bentobox.util.Util;
@PrepareForTest( {BentoBox.class, Flags.class, Util.class, Bukkit.class} )
public class EggListenerTest {
@Mock
private Location location;
@Mock
private BentoBox plugin;
@Mock
private Notifier notifier;
private EggListener el;
@Mock
private Player player;
@Mock
private World world;
@Mock
private Island island;
@Mock
private IslandWorldManager iwm;
/**
@ -73,11 +85,9 @@ public class EggListenerTest {
@Before
public void setUp() throws Exception {
// Set up plugin
plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Server server = mock(Server.class);
world = mock(World.class);
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
when(server.getWorld("world")).thenReturn(world);
when(server.getVersion()).thenReturn("BSB_Mocking");
@ -105,9 +115,7 @@ public class EggListenerTest {
FlagsManager flagsManager = new FlagsManager(plugin);
when(plugin.getFlagsManager()).thenReturn(flagsManager);
// Worlds
iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm);
@ -146,7 +154,6 @@ public class EggListenerTest {
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
// Notifier
notifier = mock(Notifier.class);
when(plugin.getNotifier()).thenReturn(notifier);
PowerMockito.mockStatic(Util.class);
@ -156,12 +163,14 @@ public class EggListenerTest {
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
// Player
player = mock(Player.class);
when(player.getLocation()).thenReturn(location);
when(player.getUniqueId()).thenReturn(UUID.randomUUID());
when(player.getName()).thenReturn("tastybento");
when(player.getWorld()).thenReturn(world);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Listener
el = new EggListener();
}
@ -184,7 +193,7 @@ public class EggListenerTest {
when(egg.getLocation()).thenReturn(location);
PlayerEggThrowEvent e = new PlayerEggThrowEvent(player, egg, false, (byte) 0, EntityType.CHICKEN);
el.onEggThrow(e);
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.eq("protection.protected"));
verify(notifier, never()).notify(any(), eq("protection.protected"));
}
/**
@ -198,7 +207,7 @@ public class EggListenerTest {
PlayerEggThrowEvent e = new PlayerEggThrowEvent(player, egg, false, (byte) 0, EntityType.CHICKEN);
el.onEggThrow(e);
assertFalse(e.isHatching());
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq("protection.protected"));
verify(notifier).notify(any(), eq("protection.protected"));
}
}

View File

@ -5,6 +5,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -141,6 +142,9 @@ public class ExperiencePickupListenerTest {
e = new EntityTargetLivingEntityEvent(entity, targetEntity, reason);
epl = new ExperiencePickupListener();
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Addon
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@ -177,6 +178,9 @@ public class HurtingListenerTest {
// Utils
when(Util.isPassiveEntity(any())).thenCallRealMethod();
when(Util.isHostileEntity(any())).thenCallRealMethod();
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// User & player
when(player.getLocation()).thenReturn(location);

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -184,6 +185,9 @@ public class InventoryListenerTest {
when(player.getName()).thenReturn("tastybento");
when(player.getWorld()).thenReturn(world);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Listener
l = new InventoryListener();
}

View File

@ -3,7 +3,10 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
@ -41,7 +44,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -130,8 +132,8 @@ public class PhysicalInteractionListenerTest {
// Fake players
Settings settings = mock(Settings.class);
Mockito.when(plugin.getSettings()).thenReturn(settings);
Mockito.when(settings.getFakePlayers()).thenReturn(new HashSet<>());
when(plugin.getSettings()).thenReturn(settings);
when(settings.getFakePlayers()).thenReturn(new HashSet<>());
// Users
User.setPlugin(plugin);
@ -151,12 +153,12 @@ public class PhysicalInteractionListenerTest {
// Player name
PlayersManager pm = mock(PlayersManager.class);
when(pm.getName(Mockito.any())).thenReturn("tastybento");
when(pm.getName(any())).thenReturn("tastybento");
when(plugin.getPlayers()).thenReturn(pm);
// World Settings
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
when(iwm.getWorldSettings(any())).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags);
@ -165,14 +167,14 @@ public class PhysicalInteractionListenerTest {
when(plugin.getIslands()).thenReturn(im);
Island island = mock(Island.class);
Optional<Island> optional = Optional.of(island);
when(im.getProtectedIslandAt(Mockito.any())).thenReturn(optional);
when(im.getProtectedIslandAt(any())).thenReturn(optional);
// Notifier
notifier = mock(Notifier.class);
when(plugin.getNotifier()).thenReturn(notifier);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
when(Util.getWorld(any())).thenReturn(mock(World.class));
// Player setup
player = mock(Player.class);
@ -186,9 +188,10 @@ public class PhysicalInteractionListenerTest {
clickedBlock = mock(Block.class);
// Addon
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
when(iwm.getAddon(any())).thenReturn(Optional.empty());
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
}
@After
@ -229,7 +232,7 @@ public class PhysicalInteractionListenerTest {
i.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.DENY));
assertTrue(e.useItemInHand().equals(Result.DENY));
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq("protection.protected"));
verify(notifier).notify(any(), eq("protection.protected"));
}
/**
@ -250,7 +253,7 @@ public class PhysicalInteractionListenerTest {
*/
@Test
public void testOnPlayerInteractFarmlandPermission() {
when(player.hasPermission(Mockito.anyString())).thenReturn(true);
when(player.hasPermission(anyString())).thenReturn(true);
when(clickedBlock.getType()).thenReturn(Material.FARMLAND);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PhysicalInteractionListener i = new PhysicalInteractionListener();
@ -269,7 +272,7 @@ public class PhysicalInteractionListenerTest {
i.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.DENY));
assertTrue(e.useItemInHand().equals(Result.DENY));
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq("protection.protected"));
verify(notifier).notify(any(), eq("protection.protected"));
}
/**

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -175,6 +176,9 @@ public class PlaceBlocksListenerTest {
when(player.getName()).thenReturn("tastybento");
when(player.getWorld()).thenReturn(world);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Listener
pbl = new PlaceBlocksListener();

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -173,6 +174,8 @@ public class TNTListenerTest {
// Addon
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
}
@Test

View File

@ -6,6 +6,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -170,6 +171,8 @@ public class ThrowingListenerTest {
when(player.getName()).thenReturn("tastybento");
when(player.getWorld()).thenReturn(world);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
}
@After

View File

@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@ -227,6 +228,9 @@ public class PVPListenerTest {
// Addon
when(iwm.getAddon(any())).thenReturn(Optional.empty());
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
}
@After
@ -1045,7 +1049,7 @@ public class PVPListenerTest {
ItemStack bow = new ItemStack(Material.CROSSBOW);
Arrow arrow = mock(Arrow.class);
EntityShootBowEvent e = new EntityShootBowEvent(creeper, bow, arrow, 0);
listener.onPlayerShootFireworkEvent(e);
listener.onPlayerShootFireworkEvent(e);
// Now damage
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(arrow, player, DamageCause.ENTITY_ATTACK, 0);
listener.onEntityDamage(en);

View File

@ -153,6 +153,8 @@ public class EnderChestListenerTest {
// Fake players
when(plugin.getSettings()).thenReturn(settings);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
}
@After

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.listeners.flags.worldsettings;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@ -197,6 +198,9 @@ public class EnterExitListenerTest {
// Flags
Flags.ENTER_EXIT_MESSAGES.setSetting(world, true);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
}
@After

View File

@ -306,6 +306,9 @@ public class IslandsManagerTest {
// PaperLib
env = new CraftBukkitEnvironment();
PaperLib.setCustomEnvironment(env);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
}
@After