Updated test units to 1.13 API

This commit is contained in:
Florian CUNY 2018-08-01 11:21:29 +02:00
parent e6418f0957
commit 138b8e7568
8 changed files with 42 additions and 107 deletions

View File

@ -96,7 +96,7 @@ public class PanelItemBuilderTest {
assertNotNull(item.getItem().getType());
SkullMeta skullMeta = (SkullMeta)item.getItem().getItemMeta();
assertEquals("tastybento",skullMeta.getOwner());
assertEquals(Material.SKULL_ITEM, item.getItem().getType());
assertEquals(Material.PLAYER_HEAD, item.getItem().getType());
}
@Test

View File

@ -709,13 +709,13 @@ public class NetherPortalsTest {
// Wrong world to start
when(loc.getWorld()).thenReturn(world);
BlockState log = mock(BlockState.class);
when(log.getType()).thenReturn(Material.LOG);
when(log.getType()).thenReturn(Material.OAK_LOG);
BlockState log2 = mock(BlockState.class);
when(log2.getType()).thenReturn(Material.LOG_2);
when(log2.getType()).thenReturn(Material.ACACIA_LOG);
BlockState leaves = mock(BlockState.class);
when(leaves.getType()).thenReturn(Material.LEAVES);
when(leaves.getType()).thenReturn(Material.OAK_LEAVES);
BlockState leaves2 = mock(BlockState.class);
when(leaves2.getType()).thenReturn(Material.LEAVES_2);
when(leaves2.getType()).thenReturn(Material.OAK_LEAVES);
List<BlockState> blocks = new ArrayList<>();
blocks.add(log);
blocks.add(log2);
@ -738,7 +738,6 @@ public class NetherPortalsTest {
Mockito.verify(log2).setType(Material.GRAVEL);
Mockito.verify(leaves).setType(Material.GLOWSTONE);
Mockito.verify(leaves2).setType(Material.GLOWSTONE);
}
}

View File

@ -152,9 +152,7 @@ public class EndermanListenerTest {
EndermanListener listener = new EndermanListener();
Block to = mock(Block.class);
Material block = Material.ACACIA_DOOR;
byte data = 0;
@SuppressWarnings("deprecation")
EntityChangeBlockEvent e = new EntityChangeBlockEvent(slime, to, block, data);
EntityChangeBlockEvent e = new EntityChangeBlockEvent(slime, to, block.createBlockData());
listener.onEndermanGrief(e);
assertFalse(e.isCancelled());
}
@ -168,9 +166,7 @@ public class EndermanListenerTest {
EndermanListener listener = new EndermanListener();
Block to = mock(Block.class);
Material block = Material.ACACIA_DOOR;
byte data = 0;
@SuppressWarnings("deprecation")
EntityChangeBlockEvent e = new EntityChangeBlockEvent(enderman, to, block, data);
EntityChangeBlockEvent e = new EntityChangeBlockEvent(enderman, to, block.createBlockData());
listener.onEndermanGrief(e);
assertFalse(e.isCancelled());
}
@ -184,9 +180,7 @@ public class EndermanListenerTest {
EndermanListener listener = new EndermanListener();
Block to = mock(Block.class);
Material block = Material.ACACIA_DOOR;
byte data = 0;
@SuppressWarnings("deprecation")
EntityChangeBlockEvent e = new EntityChangeBlockEvent(enderman, to, block, data);
EntityChangeBlockEvent e = new EntityChangeBlockEvent(enderman, to, block.createBlockData());
listener.onEndermanGrief(e);
assertFalse(e.isCancelled());
}
@ -199,9 +193,7 @@ public class EndermanListenerTest {
EndermanListener listener = new EndermanListener();
Block to = mock(Block.class);
Material block = Material.ACACIA_DOOR;
byte data = 0;
@SuppressWarnings("deprecation")
EntityChangeBlockEvent e = new EntityChangeBlockEvent(enderman, to, block, data);
EntityChangeBlockEvent e = new EntityChangeBlockEvent(enderman, to, block.createBlockData());
listener.onEndermanGrief(e);
assertTrue(e.isCancelled());
}

View File

@ -300,7 +300,7 @@ public class FireListenerTest {
assertFalse(listener.onBlockIgnite(e));
// Now set to something flammable
when(block.getType()).thenReturn(Material.WOOD);
when(block.getType()).thenReturn(Material.OAK_PLANKS);
// Disallow fire
when(island.isAllowed(Mockito.any())).thenReturn(false);

View File

@ -22,17 +22,7 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fish;
import org.bukkit.entity.LingeringPotion;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.Witch;
import org.bukkit.entity.Zombie;
import org.bukkit.entity.*;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
@ -516,14 +506,13 @@ public class PVPListenerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onFishing(org.bukkit.event.player.PlayerFishEvent)}.
*/
@Test
public void testOnFishing() {
// Fish hook
Fish hook = mock(Fish.class);
FishHook hook = mock(FishHook.class);
// Catch a zombie - fine
Entity caught = mock(Zombie.class);
PlayerFishEvent pfe = new PlayerFishEvent(player, caught, hook, null);
@ -568,7 +557,7 @@ public class PVPListenerTest {
@Test
public void testOnFishingProtectVisitors() {
// Fish hook
Fish hook = mock(Fish.class);
FishHook hook = mock(FishHook.class);
// Catch a player
PlayerFishEvent pfe = new PlayerFishEvent(player, player2, hook, null);
@ -591,7 +580,7 @@ public class PVPListenerTest {
@Test
public void testOnFishingSelfDamage() {
// Fish hook
Fish hook = mock(Fish.class);
FishHook hook = mock(FishHook.class);
// Catch a player
PlayerFishEvent pfe = new PlayerFishEvent(player, player, hook, null);
assertFalse(pfe.isCancelled());
@ -604,7 +593,7 @@ public class PVPListenerTest {
@Test
public void testOnFishingNoPVPProtectVisitors() {
// Fish hook
Fish hook = mock(Fish.class);
FishHook hook = mock(FishHook.class);
// Catch a player
PlayerFishEvent pfe = new PlayerFishEvent(player, player2, hook, null);

View File

@ -356,7 +356,7 @@ public class FlyingMobEventsTest {
* @deprecated Magic value
*/
@SuppressWarnings("deprecation")
EntityChangeBlockEvent e = new EntityChangeBlockEvent(wither, mock(Block.class), Material.AIR, (byte) 0);
EntityChangeBlockEvent e = new EntityChangeBlockEvent(wither, mock(Block.class), Material.AIR.createBlockData());
// Blocked
fme.onWitherChangeBlocks(e);
assertTrue(e.isCancelled());

View File

@ -220,25 +220,25 @@ public class IslandsManagerTest {
public void testIsSafeLocationPortals() {
when(ground.getType()).thenReturn(Material.STONE);
when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.PORTAL);
when(space2.getType()).thenReturn(Material.NETHER_PORTAL);
assertFalse(manager.isSafeLocation(location));
when(ground.getType()).thenReturn(Material.STONE);
when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.ENDER_PORTAL);
when(space2.getType()).thenReturn(Material.END_PORTAL);
assertFalse(manager.isSafeLocation(location));
when(ground.getType()).thenReturn(Material.STONE);
when(space1.getType()).thenReturn(Material.PORTAL);
when(space1.getType()).thenReturn(Material.NETHER_PORTAL);
when(space2.getType()).thenReturn(Material.AIR);
assertFalse(manager.isSafeLocation(location));
when(ground.getType()).thenReturn(Material.STONE);
when(space1.getType()).thenReturn(Material.ENDER_PORTAL);
when(space1.getType()).thenReturn(Material.END_PORTAL);
when(space2.getType()).thenReturn(Material.AIR);
assertFalse(manager.isSafeLocation(location));
when(ground.getType()).thenReturn(Material.PORTAL);
when(ground.getType()).thenReturn(Material.NETHER_PORTAL);
when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.AIR);
assertFalse(manager.isSafeLocation(location));
when(ground.getType()).thenReturn(Material.ENDER_PORTAL);
when(ground.getType()).thenReturn(Material.END_PORTAL);
when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.AIR);
assertFalse(manager.isSafeLocation(location));
@ -261,18 +261,6 @@ public class IslandsManagerTest {
when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.LAVA);
assertFalse("In lava", manager.isSafeLocation(location));
when(ground.getType()).thenReturn(Material.STATIONARY_LAVA);
when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.AIR);
assertFalse("In lava", manager.isSafeLocation(location));
when(ground.getType()).thenReturn(Material.AIR);
when(space1.getType()).thenReturn(Material.STATIONARY_LAVA);
when(space2.getType()).thenReturn(Material.AIR);
assertFalse("In lava", manager.isSafeLocation(location));
when(ground.getType()).thenReturn(Material.AIR);
when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.STATIONARY_LAVA);
assertFalse("In lava", manager.isSafeLocation(location));
}
/**
@ -280,7 +268,7 @@ public class IslandsManagerTest {
*/
@Test
public void testTrapDoor() {
when(ground.getType()).thenReturn(Material.TRAP_DOOR);
when(ground.getType()).thenReturn(Material.OAK_TRAPDOOR);
// Open trapdoor
TrapDoor trapDoor = mock(TrapDoor.class);
@ -309,12 +297,12 @@ public class IslandsManagerTest {
assertFalse("Fence :" + m.toString(), manager.isSafeLocation(location));
});
// Signs
when(ground.getType()).thenReturn(Material.SIGN_POST);
when(ground.getType()).thenReturn(Material.SIGN);
assertFalse("Sign", manager.isSafeLocation(location));
when(ground.getType()).thenReturn(Material.WALL_SIGN);
assertFalse("Sign", manager.isSafeLocation(location));
// Bad Blocks
Material[] badMats = {Material.CACTUS, Material.BOAT};
Material[] badMats = {Material.CACTUS, Material.OAK_BOAT};
Arrays.asList(badMats).forEach(m -> {
when(ground.getType()).thenReturn(m);
assertFalse("Bad mat :" + m.toString(), manager.isSafeLocation(location));
@ -342,12 +330,12 @@ public class IslandsManagerTest {
when(space2.getType()).thenReturn(Material.WALL_SIGN);
assertTrue("Wall sign 2", manager.isSafeLocation(location));
when(space1.getType()).thenReturn(Material.SIGN_POST);
when(space1.getType()).thenReturn(Material.SIGN);
when(space2.getType()).thenReturn(Material.AIR);
assertTrue("Wall sign 1", manager.isSafeLocation(location));
when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.SIGN_POST);
when(space2.getType()).thenReturn(Material.SIGN);
assertTrue("Wall sign 2", manager.isSafeLocation(location));
}
@ -456,7 +444,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIsland(java.util.UUID)}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIsland(World, UUID)}.
*/
@Test
public void testGetIsland() {
@ -497,7 +485,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIslandLocation(java.util.UUID)}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIslandLocation(World, UUID)}.
*/
@Test
public void testGetIslandLocation() {
@ -508,7 +496,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getLast()}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getLast(World)}.
*/
@Test
public void testGetLast() {
@ -519,7 +507,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getMembers(java.util.UUID)}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getMembers(World, UUID)}.
* @throws Exception
*/
@Test
@ -572,7 +560,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSafeHomeLocation(java.util.UUID, int)}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSafeHomeLocation(World, User, int)}.
*/
@Test
public void testGetSafeHomeLocation() {
@ -585,7 +573,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSpawnPoint()}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getSpawnPoint(World)}.
*/
@Test
public void testGetSpawnPoint() {
@ -602,7 +590,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#homeTeleport(org.bukkit.entity.Player, int)}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#homeTeleport(World, Player, int)}.
*/
@Test
public void testHomeTeleportPlayerInt() {
@ -618,7 +606,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#homeTeleport(org.bukkit.entity.Player, int)}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#homeTeleport(World, Player, int)}.
*/
@Test
public void testHomeTeleportPlayerIntDifferentGameMode() {
@ -648,7 +636,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isOwner(java.util.UUID)}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#isOwner(World, UUID)}.
* @throws Exception
*/
@Test
@ -753,7 +741,7 @@ public class IslandsManagerTest {
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#removePlayer(java.util.UUID)}.
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#removePlayer(World, User)}.
*/
@Test
public void testRemovePlayer() {

View File

@ -43,15 +43,11 @@ public class ItemParserTest {
PowerMockito.mockStatic(Bukkit.class);
ItemFactory itemFactory = mock(ItemFactory.class);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
spawnEggMeta = mock(SpawnEggMeta.class);
when(itemFactory.getItemMeta(Mockito.eq(Material.MONSTER_EGG))).thenReturn(spawnEggMeta);
potionMeta = mock(PotionMeta.class);
when(itemFactory.getItemMeta(Mockito.eq(Material.POTION))).thenReturn(potionMeta);
when(itemFactory.getItemMeta(Mockito.eq(Material.SPLASH_POTION))).thenReturn(potionMeta);
when(itemFactory.getItemMeta(Mockito.eq(Material.LINGERING_POTION))).thenReturn(potionMeta);
when(itemFactory.getItemMeta(Mockito.eq(Material.TIPPED_ARROW))).thenReturn(potionMeta);
bannerMeta = mock(BannerMeta.class);
when(itemFactory.getItemMeta(Mockito.eq(Material.BANNER))).thenReturn(bannerMeta);
}
@Test
@ -201,7 +197,7 @@ public class ItemParserTest {
@Test
public void testParseBannerSimple() {
ItemStack result = ItemParser.parse("BANNER:2");
assertEquals(Material.BANNER, result.getType());
assertEquals(Material.WHITE_BANNER, result.getType());
assertEquals(2, result.getAmount());
}
@ -210,9 +206,8 @@ public class ItemParserTest {
public void testParseBannerThreeArgs() {
// Germany
ItemStack result = ItemParser.parse("BANNER:1:RED");
assertEquals(Material.BANNER, result.getType());
assertEquals(Material.RED_BANNER, result.getType());
assertEquals(1, result.getAmount());
assertEquals(new MaterialData(Material.BANNER, DyeColor.RED.getDyeData()), result.getData());
}
@Test
@ -226,7 +221,7 @@ public class ItemParserTest {
public void testParseBannerTooManyColons() {
ItemStack result = ItemParser.parse("BANNER:1::::::::::::::");
Mockito.verify(bannerMeta, Mockito.never()).addPattern(Mockito.any());
assertEquals(Material.BANNER, result.getType());
assertEquals(Material.WHITE_BANNER, result.getType());
assertEquals(1, result.getAmount());
}
@ -237,16 +232,6 @@ public class ItemParserTest {
assertEquals(5, result.getAmount());
}
@Test
public void testParseTwoItemWithItemSuffixMissing() {
for (Material mat : Material.values()) {
if (mat.name().endsWith("_ITEM")) {
ItemStack r = ItemParser.parse(mat.name().replace("_ITEM", "") + ":3");
assertEquals(mat, r.getType());
}
}
}
@Test
public void testParseBadTwoItem() {
assertNull(ItemParser.parse("STNE:5"));
@ -254,8 +239,8 @@ public class ItemParserTest {
@Test
public void testParseThreeItem() {
ItemStack result = ItemParser.parse("LOG:3:2");
assertEquals(Material.LOG, result.getType());
ItemStack result = ItemParser.parse("WOODEN_SWORD:3:2");
assertEquals(Material.WOODEN_SWORD, result.getType());
assertEquals(2, result.getAmount());
assertEquals((short)3, result.getDurability());
}
@ -264,22 +249,4 @@ public class ItemParserTest {
public void testParseBadThreeItem() {
assertNull(ItemParser.parse("STNE:5:5"));
}
@Test
public void testParseThreeItemWithItemSuffixMissing() {
for (Material mat : Material.values()) {
if (mat.name().endsWith("_ITEM")) {
ItemStack r = ItemParser.parse(mat.name().replace("_ITEM", "") + ":3:2");
assertEquals(mat, r.getType());
}
}
}
@Test
public void testParseMonsterEgg() {
ItemStack result = ItemParser.parse("MONSTER_EGG:COW:2");
assertEquals(Material.MONSTER_EGG, result.getType());
assertEquals(2, result.getAmount());
Mockito.verify(spawnEggMeta).setSpawnedType(EntityType.COW);
}
}