mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-03 05:51:43 +01:00
Test class cleanup. Use Bukkit direct calls instead of Bukkit.getServer
This commit is contained in:
parent
02e8243bd0
commit
784988ca54
@ -226,7 +226,7 @@ public class BentoBox extends JavaPlugin {
|
|||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
this.addonsManager.allLoaded();
|
this.addonsManager.allLoaded();
|
||||||
// Fire plugin ready event - this should go last after everything else
|
// Fire plugin ready event - this should go last after everything else
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
|
Bukkit.getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||||
instance.log("All blueprints loaded.");
|
instance.log("All blueprints loaded.");
|
||||||
}
|
}
|
||||||
}, 0L, 1L);
|
}, 0L, 1L);
|
||||||
|
@ -65,7 +65,7 @@ public class AdminSetspawnCommand extends ConfirmableCommand {
|
|||||||
.involvedPlayer(i.getOwner())
|
.involvedPlayer(i.getOwner())
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
}
|
}
|
||||||
// If island is owned, then unregister the owner and any members
|
// If island is owned, then unregister the owner and any members
|
||||||
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m -> {
|
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m -> {
|
||||||
|
@ -70,7 +70,7 @@ public class AdminUnregisterCommand extends ConfirmableCommand {
|
|||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
// Remove all island members
|
// Remove all island members
|
||||||
new ImmutableSet.Builder<UUID>().addAll(oldIsland.getMembers().keySet()).build().forEach(m -> {
|
new ImmutableSet.Builder<UUID>().addAll(oldIsland.getMembers().keySet()).build().forEach(m -> {
|
||||||
getIslands().removePlayer(getWorld(), m);
|
getIslands().removePlayer(getWorld(), m);
|
||||||
|
@ -75,7 +75,7 @@ public class AdminTeamAddCommand extends CompositeCommand {
|
|||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
user.sendMessage("general.errors.player-has-no-island");
|
user.sendMessage("general.errors.player-has-no-island");
|
||||||
|
@ -63,7 +63,7 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
|
|||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
user.sendMessage("commands.admin.team.disband.success", TextVariables.NAME, args.get(0));
|
user.sendMessage("commands.admin.team.disband.success", TextVariables.NAME, args.get(0));
|
||||||
|
@ -77,7 +77,7 @@ public class AdminTeamKickCommand extends CompositeCommand {
|
|||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
|||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||||||
.reason(TeamEvent.Reason.JOINED)
|
.reason(TeamEvent.Reason.JOINED)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class IslandTeamInviteRejectCommand extends CompositeCommand {
|
|||||||
.reason(TeamEvent.Reason.REJECT)
|
.reason(TeamEvent.Reason.REJECT)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
|||||||
.reason(TeamEvent.Reason.KICK)
|
.reason(TeamEvent.Reason.KICK)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
|
||||||
// Add cooldown for this player and target
|
// Add cooldown for this player and target
|
||||||
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
||||||
|
@ -126,6 +126,6 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
|||||||
.reason(TeamEvent.Reason.LEAVE)
|
.reason(TeamEvent.Reason.LEAVE)
|
||||||
.involvedPlayer(user.getUniqueId())
|
.involvedPlayer(user.getUniqueId())
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -68,7 +68,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
|
|||||||
.reason(TeamEvent.Reason.SETOWNER)
|
.reason(TeamEvent.Reason.SETOWNER)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -440,76 +440,76 @@ public class IslandEvent extends IslandBaseEvent {
|
|||||||
|
|
||||||
public IslandBaseEvent build() {
|
public IslandBaseEvent build() {
|
||||||
// Call the generic event for developers who just want one event and use the Reason enum
|
// Call the generic event for developers who just want one event and use the Reason enum
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new IslandEvent(island, player, admin, location, reason));
|
Bukkit.getPluginManager().callEvent(new IslandEvent(island, player, admin, location, reason));
|
||||||
// Generate explicit events
|
// Generate explicit events
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case EXPEL:
|
case EXPEL:
|
||||||
IslandExpelEvent expel = new IslandExpelEvent(island, player, admin, location);
|
IslandExpelEvent expel = new IslandExpelEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(expel);
|
Bukkit.getPluginManager().callEvent(expel);
|
||||||
return expel;
|
return expel;
|
||||||
case BAN:
|
case BAN:
|
||||||
IslandBanEvent ban = new IslandBanEvent(island, player, admin, location);
|
IslandBanEvent ban = new IslandBanEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(ban);
|
Bukkit.getPluginManager().callEvent(ban);
|
||||||
return ban;
|
return ban;
|
||||||
case CREATE:
|
case CREATE:
|
||||||
IslandCreateEvent create = new IslandCreateEvent(island, player, admin, location, blueprintBundle);
|
IslandCreateEvent create = new IslandCreateEvent(island, player, admin, location, blueprintBundle);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(create);
|
Bukkit.getPluginManager().callEvent(create);
|
||||||
return create;
|
return create;
|
||||||
case CREATED:
|
case CREATED:
|
||||||
IslandCreatedEvent created = new IslandCreatedEvent(island, player, admin, location);
|
IslandCreatedEvent created = new IslandCreatedEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(created);
|
Bukkit.getPluginManager().callEvent(created);
|
||||||
return created;
|
return created;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
IslandDeleteEvent delete = new IslandDeleteEvent(island, player, admin, location);
|
IslandDeleteEvent delete = new IslandDeleteEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(delete);
|
Bukkit.getPluginManager().callEvent(delete);
|
||||||
return delete;
|
return delete;
|
||||||
case DELETE_CHUNKS:
|
case DELETE_CHUNKS:
|
||||||
IslandDeleteChunksEvent deleteChunks = new IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
|
IslandDeleteChunksEvent deleteChunks = new IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(deleteChunks);
|
Bukkit.getPluginManager().callEvent(deleteChunks);
|
||||||
return deleteChunks;
|
return deleteChunks;
|
||||||
case DELETED:
|
case DELETED:
|
||||||
IslandDeletedEvent deleted = new IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
|
IslandDeletedEvent deleted = new IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(deleted);
|
Bukkit.getPluginManager().callEvent(deleted);
|
||||||
return deleted;
|
return deleted;
|
||||||
case ENTER:
|
case ENTER:
|
||||||
IslandEnterEvent enter = new IslandEnterEvent(island, player, admin, location);
|
IslandEnterEvent enter = new IslandEnterEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(enter);
|
Bukkit.getPluginManager().callEvent(enter);
|
||||||
return enter;
|
return enter;
|
||||||
case EXIT:
|
case EXIT:
|
||||||
IslandExitEvent exit = new IslandExitEvent(island, player, admin, location);
|
IslandExitEvent exit = new IslandExitEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(exit);
|
Bukkit.getPluginManager().callEvent(exit);
|
||||||
return exit;
|
return exit;
|
||||||
case LOCK:
|
case LOCK:
|
||||||
IslandLockEvent lock = new IslandLockEvent(island, player, admin, location);
|
IslandLockEvent lock = new IslandLockEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(lock);
|
Bukkit.getPluginManager().callEvent(lock);
|
||||||
return lock;
|
return lock;
|
||||||
case RESET:
|
case RESET:
|
||||||
IslandResetEvent reset = new IslandResetEvent(island, player, admin, location, blueprintBundle);
|
IslandResetEvent reset = new IslandResetEvent(island, player, admin, location, blueprintBundle);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(reset);
|
Bukkit.getPluginManager().callEvent(reset);
|
||||||
return reset;
|
return reset;
|
||||||
case RESETTED:
|
case RESETTED:
|
||||||
IslandResettedEvent resetted = new IslandResettedEvent(island, player, admin, location);
|
IslandResettedEvent resetted = new IslandResettedEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(resetted);
|
Bukkit.getPluginManager().callEvent(resetted);
|
||||||
return resetted;
|
return resetted;
|
||||||
case UNBAN:
|
case UNBAN:
|
||||||
IslandUnbanEvent unban = new IslandUnbanEvent(island, player, admin, location);
|
IslandUnbanEvent unban = new IslandUnbanEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(unban);
|
Bukkit.getPluginManager().callEvent(unban);
|
||||||
return unban;
|
return unban;
|
||||||
case UNLOCK:
|
case UNLOCK:
|
||||||
IslandUnlockEvent unlock = new IslandUnlockEvent(island, player, admin, location);
|
IslandUnlockEvent unlock = new IslandUnlockEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(unlock);
|
Bukkit.getPluginManager().callEvent(unlock);
|
||||||
return unlock;
|
return unlock;
|
||||||
case REGISTERED:
|
case REGISTERED:
|
||||||
IslandRegisteredEvent reg = new IslandRegisteredEvent(island, player, admin, location);
|
IslandRegisteredEvent reg = new IslandRegisteredEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(reg);
|
Bukkit.getPluginManager().callEvent(reg);
|
||||||
return reg;
|
return reg;
|
||||||
case UNREGISTERED:
|
case UNREGISTERED:
|
||||||
IslandUnregisteredEvent unreg = new IslandUnregisteredEvent(island, player, admin, location);
|
IslandUnregisteredEvent unreg = new IslandUnregisteredEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(unreg);
|
Bukkit.getPluginManager().callEvent(unreg);
|
||||||
return unreg;
|
return unreg;
|
||||||
default:
|
default:
|
||||||
IslandGeneralEvent general = new IslandGeneralEvent(island, player, admin, location);
|
IslandGeneralEvent general = new IslandGeneralEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(general);
|
Bukkit.getPluginManager().callEvent(general);
|
||||||
return general;
|
return general;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class BentoBoxReloadCommand extends ConfirmableCommand {
|
|||||||
user.sendMessage("commands.bentobox.reload.locales-reloaded");
|
user.sendMessage("commands.bentobox.reload.locales-reloaded");
|
||||||
|
|
||||||
// Fire ready event
|
// Fire ready event
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
|
Bukkit.getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
showHelp(this, user);
|
showHelp(this, user);
|
||||||
|
@ -18,10 +18,10 @@ public class MongoDBDatabase implements DatabaseSetup {
|
|||||||
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
||||||
BentoBox plugin = BentoBox.getInstance();
|
BentoBox plugin = BentoBox.getInstance();
|
||||||
// Check if the MongoDB plugin exists
|
// Check if the MongoDB plugin exists
|
||||||
if (Bukkit.getServer().getPluginManager().getPlugin("BsbMongo") == null) {
|
if (Bukkit.getPluginManager().getPlugin("BsbMongo") == null) {
|
||||||
plugin.logError("You must install BsbMongo plugin for MongoDB support!");
|
plugin.logError("You must install BsbMongo plugin for MongoDB support!");
|
||||||
plugin.logError("See: https://github.com/tastybento/bsbMongo/releases/");
|
plugin.logError("See: https://github.com/tastybento/bsbMongo/releases/");
|
||||||
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (connector == null) {
|
if (connector == null) {
|
||||||
|
@ -87,7 +87,7 @@ public class FlagsManager {
|
|||||||
private void registerListener(@NonNull Listener l) {
|
private void registerListener(@NonNull Listener l) {
|
||||||
registeredListeners.putIfAbsent(l, false);
|
registeredListeners.putIfAbsent(l, false);
|
||||||
if (!registeredListeners.get(l)) {
|
if (!registeredListeners.get(l)) {
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(l, plugin);
|
Bukkit.getPluginManager().registerEvents(l, plugin);
|
||||||
registeredListeners.put(l, true);
|
registeredListeners.put(l, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -92,13 +92,14 @@ public class TestBentoBox {
|
|||||||
Mockito.when(server.getVersion()).thenReturn("BentoBox_Mocking");
|
Mockito.when(server.getVersion()).thenReturn("BentoBox_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pluginManager = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
|
@ -76,9 +76,10 @@ public class AddonTest {
|
|||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pluginManager = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
||||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
|
@ -3,9 +3,9 @@ package world.bentobox.bentobox.api.commands.admin;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.mockito.Mockito.any;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -14,7 +14,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
@ -109,10 +108,8 @@ public class AdminSetspawnCommandTest {
|
|||||||
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||||
|
|
||||||
// Plugin Manager
|
// Plugin Manager
|
||||||
Server server = mock(Server.class);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
// Confirmable command settings
|
// Confirmable command settings
|
||||||
Settings settings = mock(Settings.class);
|
Settings settings = mock(Settings.class);
|
||||||
|
@ -12,7 +12,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
@ -119,10 +118,8 @@ public class AdminUnregisterCommandTest {
|
|||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
// Plugin Manager
|
// Plugin Manager
|
||||||
Server server = mock(Server.class);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
@ -120,10 +119,8 @@ public class AdminTeamAddCommandTest {
|
|||||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
// Plugin Manager
|
// Plugin Manager
|
||||||
Server server = mock(Server.class);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
@ -120,10 +119,8 @@ public class AdminTeamDisbandCommandTest {
|
|||||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
// Plugin Manager
|
// Plugin Manager
|
||||||
Server server = mock(Server.class);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,7 @@ import static org.mockito.ArgumentMatchers.anyString;
|
|||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -20,7 +21,6 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
@ -130,11 +130,6 @@ public class AdminTeamKickCommandTest {
|
|||||||
// Addon
|
// Addon
|
||||||
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
// Plugin Manager
|
|
||||||
Server server = mock(Server.class);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -215,7 +210,8 @@ public class AdminTeamKickCommandTest {
|
|||||||
verify(im).removePlayer(eq(world), eq(notUUID));
|
verify(im).removePlayer(eq(world), eq(notUUID));
|
||||||
verify(pm).clearHomeLocations(eq(world), eq(notUUID));
|
verify(pm).clearHomeLocations(eq(world), eq(notUUID));
|
||||||
verify(user).sendMessage(eq("commands.admin.team.kick.success"), eq(TextVariables.NAME), eq(name), eq("[owner]"), anyString());
|
verify(user).sendMessage(eq("commands.admin.team.kick.success"), eq(TextVariables.NAME), eq(name), eq("[owner]"), anyString());
|
||||||
verify(pim).callEvent(any());
|
// Offline so event will be called twice
|
||||||
|
verify(pim, times(2)).callEvent(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@ package world.bentobox.bentobox.api.commands.admin.team;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -14,14 +17,13 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mock;
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
@ -46,10 +48,14 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
|||||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||||
public class AdminTeamSetownerCommandTest {
|
public class AdminTeamSetownerCommandTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
private CompositeCommand ac;
|
private CompositeCommand ac;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
|
@Mock
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
|
@Mock
|
||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
private UUID notUUID;
|
private UUID notUUID;
|
||||||
|
|
||||||
@ -69,7 +75,6 @@ public class AdminTeamSetownerCommandTest {
|
|||||||
// Player
|
// Player
|
||||||
Player p = mock(Player.class);
|
Player p = mock(Player.class);
|
||||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||||
user = mock(User.class);
|
|
||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
notUUID = UUID.randomUUID();
|
notUUID = UUID.randomUUID();
|
||||||
@ -82,7 +87,6 @@ public class AdminTeamSetownerCommandTest {
|
|||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
|
|
||||||
// Parent command has no aliases
|
// Parent command has no aliases
|
||||||
ac = mock(CompositeCommand.class);
|
|
||||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
// Island World Manager
|
// Island World Manager
|
||||||
@ -91,16 +95,14 @@ public class AdminTeamSetownerCommandTest {
|
|||||||
|
|
||||||
|
|
||||||
// Player has island to begin with
|
// Player has island to begin with
|
||||||
im = mock(IslandsManager.class);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
when(im.isOwner(any(),any())).thenReturn(true);
|
||||||
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
when(im.getOwner(any(),any())).thenReturn(uuid);
|
||||||
when(im.getOwner(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Has team
|
// Has team
|
||||||
pm = mock(PlayersManager.class);
|
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
|
||||||
|
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
@ -111,14 +113,12 @@ public class AdminTeamSetownerCommandTest {
|
|||||||
|
|
||||||
// Locales
|
// Locales
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
// Plugin Manager
|
// Plugin Manager
|
||||||
Server server = mock(Server.class);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,9 +140,9 @@ public class AdminTeamSetownerCommandTest {
|
|||||||
public void testExecuteUnknownPlayer() {
|
public void testExecuteUnknownPlayer() {
|
||||||
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
||||||
String[] name = {"tastybento"};
|
String[] name = {"tastybento"};
|
||||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
when(pm.getUUID(any())).thenReturn(null);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", name[0]);
|
verify(user).sendMessage("general.errors.unknown-player", "[name]", name[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,10 +152,10 @@ public class AdminTeamSetownerCommandTest {
|
|||||||
public void testExecutePlayerNotInTeam() {
|
public void testExecutePlayerNotInTeam() {
|
||||||
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
||||||
String[] name = {"tastybento"};
|
String[] name = {"tastybento"};
|
||||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(new HashSet<>());
|
when(im.getMembers(any(), any())).thenReturn(new HashSet<>());
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-in-team"));
|
verify(user).sendMessage(eq("general.errors.not-in-team"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,18 +163,18 @@ public class AdminTeamSetownerCommandTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteMakeOwnerAlreadyOwner() {
|
public void testExecuteMakeOwnerAlreadyOwner() {
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(im.inTeam(any(), any())).thenReturn(true);
|
||||||
Island is = mock(Island.class);
|
Island is = mock(Island.class);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is);
|
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
|
||||||
String[] name = {"tastybento"};
|
String[] name = {"tastybento"};
|
||||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||||
when(pm.getName(Mockito.any())).thenReturn(name[0]);
|
when(pm.getName(any())).thenReturn(name[0]);
|
||||||
|
|
||||||
when(im.getOwner(Mockito.any(), Mockito.eq(notUUID))).thenReturn(notUUID);
|
when(im.getOwner(any(), eq(notUUID))).thenReturn(notUUID);
|
||||||
|
|
||||||
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||||
Mockito.verify(user).sendMessage("commands.admin.team.setowner.already-owner", TextVariables.NAME, name[0]);
|
verify(user).sendMessage("commands.admin.team.setowner.already-owner", TextVariables.NAME, name[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,27 +183,27 @@ public class AdminTeamSetownerCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testExecuteSuccess() {
|
public void testExecuteSuccess() {
|
||||||
// Player is a team member, not an owner
|
// Player is a team member, not an owner
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(false);
|
when(im.hasIsland(any(), any(User.class))).thenReturn(false);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(im.inTeam(any(), any())).thenReturn(true);
|
||||||
Island is = mock(Island.class);
|
Island is = mock(Island.class);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is);
|
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
|
||||||
String[] name = {"tastybento"};
|
String[] name = {"tastybento"};
|
||||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||||
when(pm.getName(Mockito.any())).thenReturn(name[0]);
|
when(pm.getName(any())).thenReturn(name[0]);
|
||||||
// Owner
|
// Owner
|
||||||
when(im.getOwner(Mockito.any(), Mockito.eq(notUUID))).thenReturn(uuid);
|
when(im.getOwner(any(), eq(notUUID))).thenReturn(uuid);
|
||||||
when(pm.getName(Mockito.eq(uuid))).thenReturn("owner");
|
when(pm.getName(eq(uuid))).thenReturn("owner");
|
||||||
// Members
|
// Members
|
||||||
Set<UUID> members = new HashSet<>();
|
Set<UUID> members = new HashSet<>();
|
||||||
members.add(uuid);
|
members.add(uuid);
|
||||||
members.add(notUUID);
|
members.add(notUUID);
|
||||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members);
|
when(im.getMembers(any(), any())).thenReturn(members);
|
||||||
|
|
||||||
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
||||||
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||||
// Add other verifications
|
// Add other verifications
|
||||||
Mockito.verify(im).setOwner(Mockito.any(), Mockito.eq(user), Mockito.eq(notUUID));
|
verify(im).setOwner(any(), eq(user), eq(notUUID));
|
||||||
Mockito.verify(user).sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, name[0]);
|
verify(user).sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, name[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ package world.bentobox.bentobox.api.commands.island;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@ -24,7 +24,6 @@ import java.util.UUID;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
@ -136,10 +135,8 @@ public class IslandBanCommandTest {
|
|||||||
|
|
||||||
|
|
||||||
// Server and Plugin Manager for events
|
// Server and Plugin Manager for events
|
||||||
Server server = mock(Server.class);
|
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
when(ic.getAddon()).thenReturn(addon);
|
when(ic.getAddon()).thenReturn(addon);
|
||||||
|
@ -6,7 +6,7 @@ package world.bentobox.bentobox.api.commands.island;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -18,7 +18,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
@ -133,10 +132,8 @@ public class IslandExpelCommandTest {
|
|||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Server and Plugin Manager for events
|
// Server and Plugin Manager for events
|
||||||
Server server = mock(Server.class);
|
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
when(island.getWorld()).thenReturn(mock(World.class));
|
when(island.getWorld()).thenReturn(mock(World.class));
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
@ -125,10 +124,8 @@ public class IslandUnbanCommandTest {
|
|||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Server and Plugin Manager for events
|
// Server and Plugin Manager for events
|
||||||
Server server = mock(Server.class);
|
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ package world.bentobox.bentobox.api.commands.island.team;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@ -17,14 +17,13 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -36,6 +35,8 @@ import org.powermock.reflect.Whitebox;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
|
import world.bentobox.bentobox.api.addons.AddonDescription;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
@ -78,6 +79,8 @@ public class IslandTeamKickCommandTest {
|
|||||||
private CompositeCommand subCommand;
|
private CompositeCommand subCommand;
|
||||||
@Mock
|
@Mock
|
||||||
private Island island;
|
private Island island;
|
||||||
|
@Mock
|
||||||
|
private Addon addon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -119,6 +122,9 @@ public class IslandTeamKickCommandTest {
|
|||||||
subCommand = mock(CompositeCommand.class);
|
subCommand = mock(CompositeCommand.class);
|
||||||
Optional<CompositeCommand> optionalCommand = Optional.of(subCommand);
|
Optional<CompositeCommand> optionalCommand = Optional.of(subCommand);
|
||||||
when(ic.getSubCommand(Mockito.anyString())).thenReturn(optionalCommand);
|
when(ic.getSubCommand(Mockito.anyString())).thenReturn(optionalCommand);
|
||||||
|
when(ic.getAddon()).thenReturn(addon);
|
||||||
|
AddonDescription desc = new AddonDescription.Builder("main", "name", "version").build();
|
||||||
|
when(addon.getDescription()).thenReturn(desc);
|
||||||
|
|
||||||
// Player has island to begin with
|
// Player has island to begin with
|
||||||
im = mock(IslandsManager.class);
|
im = mock(IslandsManager.class);
|
||||||
@ -158,10 +164,8 @@ public class IslandTeamKickCommandTest {
|
|||||||
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
// Plugin Manager
|
// Plugin Manager
|
||||||
Server server = mock(Server.class);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
// Island
|
// Island
|
||||||
when(island.getUniqueId()).thenReturn("uniqueid");
|
when(island.getUniqueId()).thenReturn("uniqueid");
|
||||||
@ -171,6 +175,11 @@ public class IslandTeamKickCommandTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
User.clearUsers();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||||
*/
|
*/
|
||||||
@ -253,7 +262,6 @@ public class IslandTeamKickCommandTest {
|
|||||||
/**
|
/**
|
||||||
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||||
*/
|
*/
|
||||||
@Ignore("NPE")
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteNoConfirmation() {
|
public void testExecuteNoConfirmation() {
|
||||||
when(s.isKickConfirmation()).thenReturn(false);
|
when(s.isKickConfirmation()).thenReturn(false);
|
||||||
@ -274,7 +282,6 @@ public class IslandTeamKickCommandTest {
|
|||||||
/**
|
/**
|
||||||
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||||
*/
|
*/
|
||||||
@Ignore("NPE")
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteNoConfirmationKeepInventory() {
|
public void testExecuteNoConfirmationKeepInventory() {
|
||||||
when(iwm.isOnLeaveResetInventory(any())).thenReturn(true);
|
when(iwm.isOnLeaveResetInventory(any())).thenReturn(true);
|
||||||
@ -299,7 +306,6 @@ public class IslandTeamKickCommandTest {
|
|||||||
/**
|
/**
|
||||||
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||||
*/
|
*/
|
||||||
@Ignore("NPE")
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteNoConfirmationLoseInventoryOffline() {
|
public void testExecuteNoConfirmationLoseInventoryOffline() {
|
||||||
when(iwm.isOnLeaveResetInventory(any())).thenReturn(true);
|
when(iwm.isOnLeaveResetInventory(any())).thenReturn(true);
|
||||||
@ -350,7 +356,6 @@ public class IslandTeamKickCommandTest {
|
|||||||
/**
|
/**
|
||||||
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||||
*/
|
*/
|
||||||
@Ignore("NPE")
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteTestResets() {
|
public void testExecuteTestResets() {
|
||||||
when(s.isKickConfirmation()).thenReturn(false);
|
when(s.isKickConfirmation()).thenReturn(false);
|
||||||
@ -388,7 +393,6 @@ public class IslandTeamKickCommandTest {
|
|||||||
/**
|
/**
|
||||||
* Test method for {@link IslandTeamKickCommand#setCooldown(UUID, UUID, int)}
|
* Test method for {@link IslandTeamKickCommand#setCooldown(UUID, UUID, int)}
|
||||||
*/
|
*/
|
||||||
@Ignore("NPE")
|
|
||||||
@Test
|
@Test
|
||||||
public void testCooldown() {
|
public void testCooldown() {
|
||||||
// 10 minutes = 600 seconds
|
// 10 minutes = 600 seconds
|
||||||
|
@ -2,8 +2,8 @@ package world.bentobox.bentobox.api.commands.island.team;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@ -14,7 +14,6 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
@ -120,10 +119,8 @@ public class IslandTeamLeaveCommandTest {
|
|||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Plugin Manager
|
// Plugin Manager
|
||||||
Server server = mock(Server.class);
|
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
// Island
|
// Island
|
||||||
Island island = mock(Island.class);
|
Island island = mock(Island.class);
|
||||||
|
@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -53,8 +53,8 @@ public class PanelItemBuilderTest {
|
|||||||
Mockito.when(server.getWorld("world")).thenReturn(world);
|
Mockito.when(server.getWorld("world")).thenReturn(world);
|
||||||
Mockito.when(server.getVersion()).thenReturn("BSB_Mocking");
|
Mockito.when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
@ -16,13 +16,11 @@ import java.util.Locale;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -34,6 +32,7 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
@ -56,55 +55,47 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
|||||||
public class UserTest {
|
public class UserTest {
|
||||||
|
|
||||||
private static final String TEST_TRANSLATION = "mock translation [test]";
|
private static final String TEST_TRANSLATION = "mock translation [test]";
|
||||||
|
@Mock
|
||||||
private Player player;
|
private Player player;
|
||||||
|
@Mock
|
||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
|
@Mock
|
||||||
private LocalesManager lm;
|
private LocalesManager lm;
|
||||||
|
|
||||||
private User user;
|
private User user;
|
||||||
|
@Mock
|
||||||
private IslandWorldManager iwm;
|
private IslandWorldManager iwm;
|
||||||
private Server server;
|
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@Mock
|
||||||
|
private PluginManager pim;
|
||||||
|
@Mock
|
||||||
|
private CommandSender sender;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
plugin = mock(BentoBox.class);
|
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
|
|
||||||
server = mock(Server.class);
|
|
||||||
World world = mock(World.class);
|
|
||||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
|
||||||
when(server.getWorld("world")).thenReturn(world);
|
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
|
||||||
|
|
||||||
player = mock(Player.class);
|
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
when(server.getPlayer(Mockito.any(UUID.class))).thenReturn(player);
|
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(player);
|
||||||
when(Bukkit.getPlayer(Mockito.any(UUID.class))).thenReturn(player);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||||
when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));
|
|
||||||
|
|
||||||
iwm = mock(IslandWorldManager.class);
|
// IWM
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
// Addon
|
// Addon
|
||||||
when(iwm .getAddon(Mockito.any())).thenReturn(Optional.empty());
|
when(iwm .getAddon(any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
sender = mock(CommandSender.class);
|
|
||||||
|
|
||||||
user = User.getInstance(player);
|
user = User.getInstance(player);
|
||||||
|
|
||||||
// Locales
|
// Locales
|
||||||
lm = mock(LocalesManager.class);
|
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
when(lm.get(any(), any())).thenReturn(TEST_TRANSLATION);
|
when(lm.get(any(), any())).thenReturn(TEST_TRANSLATION);
|
||||||
when(lm.get(any())).thenReturn(TEST_TRANSLATION);
|
when(lm.get(any())).thenReturn(TEST_TRANSLATION);
|
||||||
@ -122,9 +113,6 @@ public class UserTest {
|
|||||||
User.clearUsers();
|
User.clearUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandSender sender;
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetInstanceCommandSender() {
|
public void testGetInstanceCommandSender() {
|
||||||
User user = User.getInstance(sender);
|
User user = User.getInstance(sender);
|
||||||
@ -152,7 +140,7 @@ public class UserTest {
|
|||||||
User.removePlayer(player);
|
User.removePlayer(player);
|
||||||
// If the player has been removed from the cache, then code will ask server for player
|
// If the player has been removed from the cache, then code will ask server for player
|
||||||
// Return null and check if instance is null will show that the player is not in the cache
|
// Return null and check if instance is null will show that the player is not in the cache
|
||||||
when(Bukkit.getPlayer(Mockito.any(UUID.class))).thenReturn(null);
|
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(null);
|
||||||
assertNull(User.getInstance(uuid).getPlayer());
|
assertNull(User.getInstance(uuid).getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,12 +354,12 @@ public class UserTest {
|
|||||||
for (GameMode gm: GameMode.values()) {
|
for (GameMode gm: GameMode.values()) {
|
||||||
user.setGameMode(gm);
|
user.setGameMode(gm);
|
||||||
}
|
}
|
||||||
verify(player, Mockito.times(GameMode.values().length)).setGameMode(Mockito.any());
|
verify(player, Mockito.times(GameMode.values().length)).setGameMode(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTeleport() {
|
public void testTeleport() {
|
||||||
when(player.teleport(Mockito.any(Location.class))).thenReturn(true);
|
when(player.teleport(any(Location.class))).thenReturn(true);
|
||||||
Location loc = mock(Location.class);
|
Location loc = mock(Location.class);
|
||||||
user.teleport(loc);
|
user.teleport(loc);
|
||||||
verify(player).teleport(loc);
|
verify(player).teleport(loc);
|
||||||
@ -395,7 +383,7 @@ public class UserTest {
|
|||||||
public void testGetLocalePlayer() {
|
public void testGetLocalePlayer() {
|
||||||
PlayersManager pm = mock(PlayersManager.class);
|
PlayersManager pm = mock(PlayersManager.class);
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
when(pm.getLocale(Mockito.any())).thenReturn("en-US");
|
when(pm.getLocale(any())).thenReturn("en-US");
|
||||||
|
|
||||||
// Confirm that Locale object is correctly obtained
|
// Confirm that Locale object is correctly obtained
|
||||||
assertEquals(Locale.US, user.getLocale());
|
assertEquals(Locale.US, user.getLocale());
|
||||||
@ -405,7 +393,7 @@ public class UserTest {
|
|||||||
public void testGetLocaleConsole() {
|
public void testGetLocaleConsole() {
|
||||||
PlayersManager pm = mock(PlayersManager.class);
|
PlayersManager pm = mock(PlayersManager.class);
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
when(pm.getLocale(Mockito.any())).thenReturn("en-US");
|
when(pm.getLocale(any())).thenReturn("en-US");
|
||||||
|
|
||||||
// Confirm that Locale object is correctly obtained
|
// Confirm that Locale object is correctly obtained
|
||||||
Locale locale = Locale.US;
|
Locale locale = Locale.US;
|
||||||
|
@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -48,14 +48,14 @@ public class FlagAdapterTest {
|
|||||||
|
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemMeta meta = mock(ItemMeta.class);
|
ItemMeta meta = mock(ItemMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
||||||
|
@ -61,13 +61,13 @@ public class ItemStackTypeAdapterTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemMeta meta = mock(ItemMeta.class);
|
ItemMeta meta = mock(ItemMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
||||||
|
@ -2,8 +2,8 @@ package world.bentobox.bentobox.listeners.flags.protection;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@ -112,14 +112,14 @@ public class BreakBlocksListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemMeta meta = mock(ItemMeta.class);
|
ItemMeta meta = mock(ItemMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
||||||
|
@ -5,7 +5,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -97,15 +97,15 @@ public class BreedingListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
//Bukkit.setServer(server);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
|
@ -89,14 +89,14 @@ public class BucketListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemMeta meta = mock(ItemMeta.class);
|
ItemMeta meta = mock(ItemMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package world.bentobox.bentobox.listeners.flags.protection;
|
package world.bentobox.bentobox.listeners.flags.protection;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -82,14 +82,14 @@ public class EggListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemMeta meta = mock(ItemMeta.class);
|
ItemMeta meta = mock(ItemMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
||||||
|
@ -2,7 +2,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -77,8 +77,8 @@ public class FireListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
@ -103,14 +103,14 @@ public class HurtingListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
|
@ -103,14 +103,14 @@ public class InventoryListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemMeta meta = mock(ItemMeta.class);
|
ItemMeta meta = mock(ItemMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
||||||
|
@ -2,7 +2,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -90,14 +90,14 @@ public class PhysicalInteractionListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package world.bentobox.bentobox.listeners.flags.protection;
|
package world.bentobox.bentobox.listeners.flags.protection;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -98,14 +95,14 @@ public class PlaceBlocksListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemMeta meta = mock(ItemMeta.class);
|
ItemMeta meta = mock(ItemMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
||||||
|
@ -2,7 +2,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -84,14 +84,14 @@ public class TNTListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
|
@ -5,7 +5,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -87,14 +87,14 @@ public class ThrowingListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemMeta meta = mock(ItemMeta.class);
|
ItemMeta meta = mock(ItemMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
when(itemFactory.getItemMeta(any())).thenReturn(meta);
|
||||||
|
@ -76,8 +76,7 @@ public class MobSpawnListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
@ -87,6 +86,8 @@ public class MobSpawnListenerTest {
|
|||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
location = mock(Location.class);
|
location = mock(Location.class);
|
||||||
when(location.getWorld()).thenReturn(world);
|
when(location.getWorld()).thenReturn(world);
|
||||||
when(location.getBlockX()).thenReturn(0);
|
when(location.getBlockX()).thenReturn(0);
|
||||||
|
@ -6,7 +6,7 @@ package world.bentobox.bentobox.listeners.flags.worldsettings;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -81,8 +81,7 @@ public class ChestDamageListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
@ -90,6 +89,7 @@ public class ChestDamageListenerTest {
|
|||||||
// Bukkit
|
// Bukkit
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
|
@ -5,7 +5,7 @@ package world.bentobox.bentobox.listeners.flags.worldsettings;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -74,14 +74,14 @@ public class EndermanListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
|
@ -15,7 +15,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
@ -93,10 +92,8 @@ public class EnterExitListenerTest {
|
|||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
Server server = mock(Server.class);
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
when(server.getPluginManager()).thenReturn(pim);
|
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
Settings s = mock(Settings.class);
|
Settings s = mock(Settings.class);
|
||||||
|
@ -76,15 +76,14 @@ public class ItemFrameListenerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
@ -2,7 +2,7 @@ package world.bentobox.bentobox.listeners.flags.worldsettings;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -29,7 +30,9 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import org.powermock.reflect.Whitebox;
|
import org.powermock.reflect.Whitebox;
|
||||||
@ -43,17 +46,25 @@ import world.bentobox.bentobox.managers.LocalesManager;
|
|||||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({BentoBox.class, PlayerEvent.class, PlayerInteractEvent.class})
|
@PrepareForTest({BentoBox.class, PlayerEvent.class, PlayerInteractEvent.class, Bukkit.class})
|
||||||
public class ObsidianScoopingListenerTest {
|
public class ObsidianScoopingListenerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
private World world;
|
private World world;
|
||||||
private ObsidianScoopingListener listener;
|
private ObsidianScoopingListener listener;
|
||||||
|
@Mock
|
||||||
private ItemStack item;
|
private ItemStack item;
|
||||||
|
@Mock
|
||||||
private Block clickedBlock;
|
private Block clickedBlock;
|
||||||
|
@Mock
|
||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
|
@Mock
|
||||||
private Player who;
|
private Player who;
|
||||||
|
@Mock
|
||||||
private IslandWorldManager iwm;
|
private IslandWorldManager iwm;
|
||||||
|
@Mock
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
|
@Mock
|
||||||
private LocalesManager lm;
|
private LocalesManager lm;
|
||||||
private Material inHand;
|
private Material inHand;
|
||||||
private Material block;
|
private Material block;
|
||||||
@ -61,33 +72,26 @@ public class ObsidianScoopingListenerTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
plugin = mock(BentoBox.class);
|
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
|
||||||
// Mock world
|
|
||||||
world = mock(World.class);
|
|
||||||
|
|
||||||
// Mock server
|
// Mock server
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pluginManager = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
||||||
|
|
||||||
// Mock item factory (for itemstacks)
|
// Mock item factory (for itemstacks)
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
// Set the server to the mock
|
|
||||||
//Bukkit.setServer(server);
|
|
||||||
|
|
||||||
// Create new object
|
// Create new object
|
||||||
listener = new ObsidianScoopingListener();
|
listener = new ObsidianScoopingListener();
|
||||||
|
|
||||||
// Mock player
|
// Mock player
|
||||||
who = mock(Player.class);
|
|
||||||
when(who.getWorld()).thenReturn(world);
|
when(who.getWorld()).thenReturn(world);
|
||||||
|
|
||||||
Location location = mock(Location.class);
|
Location location = mock(Location.class);
|
||||||
@ -100,19 +104,15 @@ public class ObsidianScoopingListenerTest {
|
|||||||
when(who.getInventory()).thenReturn(mock(PlayerInventory.class));
|
when(who.getInventory()).thenReturn(mock(PlayerInventory.class));
|
||||||
|
|
||||||
// Worlds
|
// Worlds
|
||||||
iwm = mock(IslandWorldManager.class);
|
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
when(iwm.getIslandWorld(Mockito.any())).thenReturn(world);
|
when(iwm.getIslandWorld(Mockito.any())).thenReturn(world);
|
||||||
when(iwm.getNetherWorld(Mockito.any())).thenReturn(world);
|
when(iwm.getNetherWorld(Mockito.any())).thenReturn(world);
|
||||||
when(iwm.getEndWorld(Mockito.any())).thenReturn(world);
|
when(iwm.getEndWorld(Mockito.any())).thenReturn(world);
|
||||||
|
|
||||||
// Mock up IslandsManager
|
// Mock up IslandsManager
|
||||||
im = mock(IslandsManager.class);
|
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Mock up items and blocks
|
// Mock up items and blocks
|
||||||
item = mock(ItemStack.class);
|
|
||||||
clickedBlock = mock(Block.class);
|
|
||||||
when(clickedBlock.getX()).thenReturn(0);
|
when(clickedBlock.getX()).thenReturn(0);
|
||||||
when(clickedBlock.getY()).thenReturn(0);
|
when(clickedBlock.getY()).thenReturn(0);
|
||||||
when(clickedBlock.getZ()).thenReturn(0);
|
when(clickedBlock.getZ()).thenReturn(0);
|
||||||
@ -131,7 +131,6 @@ public class ObsidianScoopingListenerTest {
|
|||||||
when(who.getGameMode()).thenReturn(GameMode.SURVIVAL);
|
when(who.getGameMode()).thenReturn(GameMode.SURVIVAL);
|
||||||
|
|
||||||
// Locales
|
// Locales
|
||||||
lm = mock(LocalesManager.class);
|
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||||
|
|
||||||
|
@ -6,8 +6,10 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -25,7 +27,7 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mock;
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
@ -41,8 +43,10 @@ import world.bentobox.bentobox.lists.Flags;
|
|||||||
public class FlagsManagerTest {
|
public class FlagsManagerTest {
|
||||||
|
|
||||||
|
|
||||||
private static BentoBox plugin;
|
private BentoBox plugin;
|
||||||
private static Server server;
|
private Server server;
|
||||||
|
@Mock
|
||||||
|
private PluginManager pluginManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@ -63,15 +67,12 @@ public class FlagsManagerTest {
|
|||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
||||||
|
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||||
@ -111,12 +112,12 @@ public class FlagsManagerTest {
|
|||||||
Flag originalFlag = new Flag.Builder("ORIGINAL", Material.EMERALD_BLOCK).listener(ol).build();
|
Flag originalFlag = new Flag.Builder("ORIGINAL", Material.EMERALD_BLOCK).listener(ol).build();
|
||||||
assertTrue(fm.registerFlag(originalFlag));
|
assertTrue(fm.registerFlag(originalFlag));
|
||||||
// Verify registered
|
// Verify registered
|
||||||
Mockito.verify(server).getPluginManager();
|
verify(pluginManager).registerEvents(any(), eq(plugin));
|
||||||
// Register another flag with same listener
|
// Register another flag with same listener
|
||||||
Flag originalFlag2 = new Flag.Builder("ORIGINAL2", Material.COAL_ORE).listener(ol).build();
|
Flag originalFlag2 = new Flag.Builder("ORIGINAL2", Material.COAL_ORE).listener(ol).build();
|
||||||
assertTrue(fm.registerFlag(originalFlag2));
|
assertTrue(fm.registerFlag(originalFlag2));
|
||||||
// Verify registered only once
|
// Verify registered only once
|
||||||
Mockito.verify(server).getPluginManager();
|
verify(pluginManager).registerEvents(any(), eq(plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
class OriginalListener implements Listener {
|
class OriginalListener implements Listener {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package world.bentobox.bentobox.util.teleport;
|
package world.bentobox.bentobox.util.teleport;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ public class SafeSpotTeleportTest {
|
|||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pluginManager = mock(PluginManager.class);
|
||||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
||||||
|
|
||||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user