mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-29 06:05:13 +01:00
Fix tests
This commit is contained in:
parent
901295b0ea
commit
64ccfaa37f
@ -16,7 +16,6 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
import world.bentobox.bentobox.api.flags.Flag.Mode;
|
|
||||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
|
||||||
@ -228,7 +227,7 @@ public class AdminSettingsCommand extends CompositeCommand {
|
|||||||
new TabbedPanelBuilder()
|
new TabbedPanelBuilder()
|
||||||
.user(user)
|
.user(user)
|
||||||
.world(getWorld())
|
.world(getWorld())
|
||||||
.tab(1, new SettingsTab(getWorld(), user, Flag.Type.WORLD_SETTING))
|
.tab(1, new SettingsTab(getWorld(), user, Flag.Type.WORLD_SETTING, Flag.Mode.EXPERT))
|
||||||
.tab(2, new WorldDefaultSettingsTab(getWorld(), user))
|
.tab(2, new WorldDefaultSettingsTab(getWorld(), user))
|
||||||
.startingSlot(1)
|
.startingSlot(1)
|
||||||
.size(54)
|
.size(54)
|
||||||
@ -239,8 +238,8 @@ public class AdminSettingsCommand extends CompositeCommand {
|
|||||||
new TabbedPanelBuilder()
|
new TabbedPanelBuilder()
|
||||||
.user(user)
|
.user(user)
|
||||||
.world(island.getWorld())
|
.world(island.getWorld())
|
||||||
.island(island).tab(1, new SettingsTab(user, Flag.Type.PROTECTION))
|
.island(island).tab(1, new SettingsTab(getWorld(), user, Flag.Type.PROTECTION, Flag.Mode.EXPERT))
|
||||||
.tab(2, new SettingsTab(user, Flag.Type.SETTING))
|
.tab(2, new SettingsTab(getWorld(), user, Flag.Type.SETTING, Flag.Mode.EXPERT))
|
||||||
.startingSlot(1)
|
.startingSlot(1)
|
||||||
.size(54)
|
.size(54)
|
||||||
.build().openPanel();
|
.build().openPanel();
|
||||||
|
@ -49,7 +49,8 @@ public class IslandSettingsCommand extends CompositeCommand {
|
|||||||
.user(user)
|
.user(user)
|
||||||
.island(island)
|
.island(island)
|
||||||
.world(island.getWorld())
|
.world(island.getWorld())
|
||||||
.tab(1, new SettingsTab(user, Flag.Type.PROTECTION)).tab(2, new SettingsTab(user, Flag.Type.SETTING))
|
.tab(1, new SettingsTab(getWorld(), user, Flag.Type.PROTECTION))
|
||||||
|
.tab(2, new SettingsTab(getWorld(), user, Flag.Type.SETTING))
|
||||||
.startingSlot(1)
|
.startingSlot(1)
|
||||||
.size(54)
|
.size(54)
|
||||||
.hideIfEmpty()
|
.hideIfEmpty()
|
||||||
|
@ -50,17 +50,6 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||||||
|
|
||||||
private Map<UUID, Flag.Mode> currentMode = new HashMap<>();
|
private Map<UUID, Flag.Mode> currentMode = new HashMap<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* Show a tab of settings
|
|
||||||
* @param user - user who is viewing the tab
|
|
||||||
* @param type - flag type
|
|
||||||
*/
|
|
||||||
public SettingsTab(User user, Type type) {
|
|
||||||
this.user = user;
|
|
||||||
this.type = type;
|
|
||||||
// Island and world are set when the parent is set.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a tab of settings
|
* Show a tab of settings
|
||||||
* @param world - world
|
* @param world - world
|
||||||
@ -73,6 +62,21 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a tab of settings
|
||||||
|
* @param world - world
|
||||||
|
* @param user - user who is viewing the tab
|
||||||
|
* @param type - flag type
|
||||||
|
* @param defaultMode - the default mode to show
|
||||||
|
* @since 2.4.0
|
||||||
|
*/
|
||||||
|
public SettingsTab(World world, User user, Type type, Flag.Mode defaultMode) {
|
||||||
|
this.world = world;
|
||||||
|
this.user = user;
|
||||||
|
this.type = type;
|
||||||
|
currentMode.put(user.getUniqueId(), defaultMode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list of flags that will be shown in this panel
|
* @return list of flags that will be shown in this panel
|
||||||
*/
|
*/
|
||||||
|
@ -32,10 +32,13 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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;
|
||||||
|
|
||||||
|
import com.github.puregero.multilib.MultiLib;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.exceptions.InvalidAddonDescriptionException;
|
import world.bentobox.bentobox.api.addons.exceptions.InvalidAddonDescriptionException;
|
||||||
import world.bentobox.bentobox.managers.AddonsManager;
|
import world.bentobox.bentobox.managers.AddonsManager;
|
||||||
@ -46,7 +49,7 @@ import world.bentobox.bentobox.managers.AddonsManager;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( { BentoBox.class, Bukkit.class })
|
@PrepareForTest({ BentoBox.class, Bukkit.class, MultiLib.class })
|
||||||
public class AddonClassLoaderTest {
|
public class AddonClassLoaderTest {
|
||||||
|
|
||||||
private enum mandatoryTags {
|
private enum mandatoryTags {
|
||||||
@ -80,6 +83,7 @@ public class AddonClassLoaderTest {
|
|||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
plugin = mock(BentoBox.class);
|
plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
@ -44,13 +44,15 @@ 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;
|
||||||
|
|
||||||
|
import com.github.puregero.multilib.MultiLib;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.managers.AddonsManager;
|
import world.bentobox.bentobox.managers.AddonsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( { BentoBox.class, Bukkit.class })
|
@PrepareForTest({ BentoBox.class, Bukkit.class, MultiLib.class })
|
||||||
public class AddonTest {
|
public class AddonTest {
|
||||||
|
|
||||||
public static int BUFFER_SIZE = 10240;
|
public static int BUFFER_SIZE = 10240;
|
||||||
@ -90,6 +92,8 @@ public class AddonTest {
|
|||||||
// Addons manager
|
// Addons manager
|
||||||
when(plugin.getAddonsManager()).thenReturn(am);
|
when(plugin.getAddonsManager()).thenReturn(am);
|
||||||
|
|
||||||
|
// MultiLib
|
||||||
|
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
|
||||||
|
|
||||||
// Mock item factory (for itemstacks)
|
// Mock item factory (for itemstacks)
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
|
@ -278,8 +278,6 @@ public class IslandTeamSetownerCommandTest {
|
|||||||
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
||||||
assertTrue(its.execute(user, "", List.of("tastybento")));
|
assertTrue(its.execute(user, "", List.of("tastybento")));
|
||||||
verify(im).setOwner(any(), eq(user), eq(target));
|
verify(im).setOwner(any(), eq(user), eq(target));
|
||||||
PowerMockito.verifyStatic(IslandsManager.class);
|
|
||||||
IslandsManager.updateIsland(island);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -295,8 +293,6 @@ public class IslandTeamSetownerCommandTest {
|
|||||||
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
||||||
assertTrue(its.execute(user, "", List.of("tastybento")));
|
assertTrue(its.execute(user, "", List.of("tastybento")));
|
||||||
verify(im).setOwner(any(), eq(user), eq(target));
|
verify(im).setOwner(any(), eq(user), eq(target));
|
||||||
PowerMockito.verifyStatic(IslandsManager.class);
|
|
||||||
IslandsManager.updateIsland(island);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,8 +220,6 @@ public class JoinLeaveListenerTest {
|
|||||||
jll = new JoinLeaveListener(plugin);
|
jll = new JoinLeaveListener(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
User.clearUsers();
|
User.clearUsers();
|
||||||
@ -237,7 +235,7 @@ public class JoinLeaveListenerTest {
|
|||||||
PlayerJoinEvent event = new PlayerJoinEvent(player, "");
|
PlayerJoinEvent event = new PlayerJoinEvent(player, "");
|
||||||
jll.onPlayerJoin(event);
|
jll.onPlayerJoin(event);
|
||||||
// Verify
|
// Verify
|
||||||
verify(pm, times(2)).getPlayer(any());
|
verify(pm, times(3)).getPlayer(any());
|
||||||
verify(player, never()).sendMessage(anyString());
|
verify(player, never()).sendMessage(anyString());
|
||||||
// Verify resets
|
// Verify resets
|
||||||
verify(pm).setResets(eq(world), any(), eq(0));
|
verify(pm).setResets(eq(world), any(), eq(0));
|
||||||
@ -354,7 +352,7 @@ public class JoinLeaveListenerTest {
|
|||||||
PlayerJoinEvent event = new PlayerJoinEvent(player, "");
|
PlayerJoinEvent event = new PlayerJoinEvent(player, "");
|
||||||
jll.onPlayerJoin(event);
|
jll.onPlayerJoin(event);
|
||||||
// Verify
|
// Verify
|
||||||
verify(pm, times(2)).getPlayer(any());
|
verify(pm, times(3)).getPlayer(any());
|
||||||
verify(player).sendMessage(eq("commands.island.create.on-first-login"));
|
verify(player).sendMessage(eq("commands.island.create.on-first-login"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ 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;
|
||||||
|
|
||||||
|
import com.github.puregero.multilib.MultiLib;
|
||||||
|
|
||||||
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.Addon;
|
||||||
@ -49,7 +51,7 @@ import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
|
|||||||
import world.bentobox.bentobox.database.objects.DataObject;
|
import world.bentobox.bentobox.database.objects.DataObject;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( {Bukkit.class, BentoBox.class, DefaultPermissions.class} )
|
@PrepareForTest({ Bukkit.class, BentoBox.class, DefaultPermissions.class, MultiLib.class })
|
||||||
public class AddonsManagerTest {
|
public class AddonsManagerTest {
|
||||||
|
|
||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
@ -81,6 +83,8 @@ public class AddonsManagerTest {
|
|||||||
when(plugin.getSettings()).thenReturn(s);
|
when(plugin.getSettings()).thenReturn(s);
|
||||||
|
|
||||||
PowerMockito.mockStatic(DefaultPermissions.class);
|
PowerMockito.mockStatic(DefaultPermissions.class);
|
||||||
|
|
||||||
|
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,6 +45,8 @@ 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 com.github.puregero.multilib.MultiLib;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.addons.AddonDescription;
|
import world.bentobox.bentobox.api.addons.AddonDescription;
|
||||||
@ -62,7 +64,7 @@ import world.bentobox.bentobox.database.objects.Island;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( {Bukkit.class, BentoBox.class, BlueprintPaster.class} )
|
@PrepareForTest({ Bukkit.class, BentoBox.class, BlueprintPaster.class, MultiLib.class })
|
||||||
public class BlueprintsManagerTest {
|
public class BlueprintsManagerTest {
|
||||||
|
|
||||||
public static int BUFFER_SIZE = 10240;
|
public static int BUFFER_SIZE = 10240;
|
||||||
@ -95,10 +97,12 @@ public class BlueprintsManagerTest {
|
|||||||
private int times;
|
private int times;
|
||||||
@Mock
|
@Mock
|
||||||
private Server server;
|
private Server server;
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
// Multilib
|
||||||
|
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
|
||||||
|
|
||||||
// Make the addon
|
// Make the addon
|
||||||
dataFolder = new File("dataFolder");
|
dataFolder = new File("dataFolder");
|
||||||
jarFile = new File("addon.jar");
|
jarFile = new File("addon.jar");
|
||||||
|
@ -55,7 +55,6 @@ 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.flags.Flag.Mode;
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
||||||
import world.bentobox.bentobox.database.Database;
|
import world.bentobox.bentobox.database.Database;
|
||||||
|
Loading…
Reference in New Issue
Block a user