mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 03:35:11 +01:00
Fix for random test failures.
This commit is contained in:
parent
945bfa66ee
commit
546cf2c9b9
@ -21,10 +21,12 @@ import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
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.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@ -57,6 +59,7 @@ import world.bentobox.bentobox.util.Util;
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public abstract class AbstractCommonSetup {
|
||||
|
||||
protected UUID uuid = UUID.randomUUID();
|
||||
@ -136,7 +139,7 @@ public abstract class AbstractCommonSetup {
|
||||
|
||||
// Island - nothing is allowed by default
|
||||
when(island.isAllowed(any())).thenReturn(false);
|
||||
when(island.isAllowed(any(), any())).thenReturn(false);
|
||||
when(island.isAllowed(any(User.class), any())).thenReturn(false);
|
||||
when(island.getOwner()).thenReturn(uuid);
|
||||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid));
|
||||
|
||||
|
@ -69,6 +69,10 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
|
||||
position = new Vector(10,10,10);
|
||||
when(inv.getItemInMainHand()).thenReturn(new ItemStack(Material.NAME_TAG));
|
||||
|
||||
// Initialize the Flags class. This is a workaround to prevent weird errors when mocking
|
||||
// I think it's because the flag class needs to be initialized before use in argument matchers
|
||||
Flags.TRADING.setDefaultSetting(false);
|
||||
|
||||
// Class under test
|
||||
eil = new EntityInteractListener();
|
||||
}
|
||||
@ -91,7 +95,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
|
||||
*/
|
||||
@Test
|
||||
public void testOnPlayerInteractAtEntityArmorStandAllowed() {
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
when(island.isAllowed(any(User.class), any())).thenReturn(true);
|
||||
clickedEntity = mock(ArmorStand.class);
|
||||
when(clickedEntity.getLocation()).thenReturn(location);
|
||||
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position, hand);
|
||||
@ -118,7 +122,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
|
||||
*/
|
||||
@Test
|
||||
public void testOnPlayerInteractEntityHorseAllowed() {
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
when(island.isAllowed(any(User.class), any())).thenReturn(true);
|
||||
clickedEntity = mock(Horse.class);
|
||||
when(clickedEntity.getLocation()).thenReturn(location);
|
||||
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
|
||||
@ -145,7 +149,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
|
||||
*/
|
||||
@Test
|
||||
public void testOnPlayerInteractEntityMinecartAllowed() {
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
when(island.isAllowed(any(User.class), any())).thenReturn(true);
|
||||
clickedEntity = mock(RideableMinecart.class);
|
||||
when(clickedEntity.getLocation()).thenReturn(location);
|
||||
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
|
||||
@ -172,7 +176,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
|
||||
*/
|
||||
@Test
|
||||
public void testOnPlayerInteractEntityBoatAllowed() {
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
when(island.isAllowed(any(User.class), any())).thenReturn(true);
|
||||
clickedEntity = mock(Boat.class);
|
||||
when(clickedEntity.getLocation()).thenReturn(location);
|
||||
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
|
||||
@ -199,7 +203,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
|
||||
*/
|
||||
@Test
|
||||
public void testOnPlayerInteractAtEntityVillagerAllowed() {
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
when(island.isAllowed(any(User.class), any())).thenReturn(true);
|
||||
clickedEntity = mock(Villager.class);
|
||||
when(clickedEntity.getLocation()).thenReturn(location);
|
||||
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
|
||||
@ -212,9 +216,10 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.EntityInteractListener#onPlayerInteractEntity(org.bukkit.event.player.PlayerInteractAtEntityEvent)}.
|
||||
*/
|
||||
@Test
|
||||
|
||||
public void testOnPlayerInteractEntityNamingVillagerAllowedNoTrading() {
|
||||
when(island.isAllowed(any(), eq(Flags.TRADING))).thenReturn(false);
|
||||
when(island.isAllowed(any(), eq(Flags.NAME_TAG))).thenReturn(true);
|
||||
when(island.isAllowed(any(User.class), eq(Flags.TRADING))).thenReturn(false);
|
||||
when(island.isAllowed(any(User.class), eq(Flags.NAME_TAG))).thenReturn(true);
|
||||
clickedEntity = mock(Villager.class);
|
||||
when(clickedEntity.getLocation()).thenReturn(location);
|
||||
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
|
||||
@ -271,8 +276,9 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.EntityInteractListener#onPlayerInteractEntity(org.bukkit.event.player.PlayerInteractAtEntityEvent)}.
|
||||
*/
|
||||
@Test
|
||||
|
||||
public void testOnPlayerInteractEntityNamingWanderingTraderAllowedNoTrading() {
|
||||
when(island.isAllowed(any(User.class),
|
||||
when(island.isAllowed(any(),
|
||||
eq(Flags.TRADING))).thenReturn(false);
|
||||
when(island.isAllowed(any(User.class),
|
||||
eq(Flags.NAME_TAG))).thenReturn(true);
|
||||
@ -289,6 +295,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.EntityInteractListener#onPlayerInteractEntity(org.bukkit.event.player.PlayerInteractAtEntityEvent)}.
|
||||
*/
|
||||
@Test
|
||||
|
||||
public void testOnPlayerInteractEntityNamingWanderingTraderAllowedTradingNoNaming() {
|
||||
when(island.isAllowed(any(User.class), eq(Flags.TRADING))).thenReturn(true);
|
||||
when(island.isAllowed(any(User.class), eq(Flags.NAME_TAG))).thenReturn(false);
|
||||
|
Loading…
Reference in New Issue
Block a user