Fix tests

This commit is contained in:
tastybento 2024-04-28 09:20:53 -07:00
parent 901295b0ea
commit 64ccfaa37f
10 changed files with 44 additions and 31 deletions

View File

@ -16,7 +16,6 @@ import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
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.localization.TextVariables;
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
@ -228,7 +227,7 @@ public class AdminSettingsCommand extends CompositeCommand {
new TabbedPanelBuilder()
.user(user)
.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))
.startingSlot(1)
.size(54)
@ -239,8 +238,8 @@ public class AdminSettingsCommand extends CompositeCommand {
new TabbedPanelBuilder()
.user(user)
.world(island.getWorld())
.island(island).tab(1, new SettingsTab(user, Flag.Type.PROTECTION))
.tab(2, new SettingsTab(user, Flag.Type.SETTING))
.island(island).tab(1, new SettingsTab(getWorld(), user, Flag.Type.PROTECTION, Flag.Mode.EXPERT))
.tab(2, new SettingsTab(getWorld(), user, Flag.Type.SETTING, Flag.Mode.EXPERT))
.startingSlot(1)
.size(54)
.build().openPanel();

View File

@ -49,7 +49,8 @@ public class IslandSettingsCommand extends CompositeCommand {
.user(user)
.island(island)
.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)
.size(54)
.hideIfEmpty()

View File

@ -50,17 +50,6 @@ public class SettingsTab implements Tab, ClickHandler {
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
* @param world - world
@ -73,6 +62,21 @@ public class SettingsTab implements Tab, ClickHandler {
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
*/

View File

@ -32,10 +32,13 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.exceptions.InvalidAddonDescriptionException;
import world.bentobox.bentobox.managers.AddonsManager;
@ -46,7 +49,7 @@ import world.bentobox.bentobox.managers.AddonsManager;
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest( { BentoBox.class, Bukkit.class })
@PrepareForTest({ BentoBox.class, Bukkit.class, MultiLib.class })
public class AddonClassLoaderTest {
private enum mandatoryTags {
@ -80,6 +83,7 @@ public class AddonClassLoaderTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
// Set up plugin
plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);

View File

@ -44,13 +44,15 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.managers.AddonsManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlayersManager;
@RunWith(PowerMockRunner.class)
@PrepareForTest( { BentoBox.class, Bukkit.class })
@PrepareForTest({ BentoBox.class, Bukkit.class, MultiLib.class })
public class AddonTest {
public static int BUFFER_SIZE = 10240;
@ -90,6 +92,8 @@ public class AddonTest {
// Addons manager
when(plugin.getAddonsManager()).thenReturn(am);
// MultiLib
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
// Mock item factory (for itemstacks)
ItemFactory itemFactory = mock(ItemFactory.class);

View File

@ -278,8 +278,6 @@ public class IslandTeamSetownerCommandTest {
assertTrue(its.canExecute(user, "", List.of("tastybento")));
assertTrue(its.execute(user, "", List.of("tastybento")));
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.execute(user, "", List.of("tastybento")));
verify(im).setOwner(any(), eq(user), eq(target));
PowerMockito.verifyStatic(IslandsManager.class);
IslandsManager.updateIsland(island);
}
/**

View File

@ -220,8 +220,6 @@ public class JoinLeaveListenerTest {
jll = new JoinLeaveListener(plugin);
}
/**
*/
@After
public void tearDown() {
User.clearUsers();
@ -237,7 +235,7 @@ public class JoinLeaveListenerTest {
PlayerJoinEvent event = new PlayerJoinEvent(player, "");
jll.onPlayerJoin(event);
// Verify
verify(pm, times(2)).getPlayer(any());
verify(pm, times(3)).getPlayer(any());
verify(player, never()).sendMessage(anyString());
// Verify resets
verify(pm).setResets(eq(world), any(), eq(0));
@ -354,7 +352,7 @@ public class JoinLeaveListenerTest {
PlayerJoinEvent event = new PlayerJoinEvent(player, "");
jll.onPlayerJoin(event);
// Verify
verify(pm, times(2)).getPlayer(any());
verify(pm, times(3)).getPlayer(any());
verify(player).sendMessage(eq("commands.island.create.on-first-login"));
}

View File

@ -37,6 +37,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
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;
@RunWith(PowerMockRunner.class)
@PrepareForTest( {Bukkit.class, BentoBox.class, DefaultPermissions.class} )
@PrepareForTest({ Bukkit.class, BentoBox.class, DefaultPermissions.class, MultiLib.class })
public class AddonsManagerTest {
private BentoBox plugin;
@ -81,6 +83,8 @@ public class AddonsManagerTest {
when(plugin.getSettings()).thenReturn(s);
PowerMockito.mockStatic(DefaultPermissions.class);
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
}
/**

View File

@ -45,6 +45,8 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.AddonDescription;
@ -62,7 +64,7 @@ import world.bentobox.bentobox.database.objects.Island;
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest( {Bukkit.class, BentoBox.class, BlueprintPaster.class} )
@PrepareForTest({ Bukkit.class, BentoBox.class, BlueprintPaster.class, MultiLib.class })
public class BlueprintsManagerTest {
public static int BUFFER_SIZE = 10240;
@ -95,10 +97,12 @@ public class BlueprintsManagerTest {
private int times;
@Mock
private Server server;
/**
*/
@Before
public void setUp() throws Exception {
// Multilib
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
// Make the addon
dataFolder = new File("dataFolder");
jarFile = new File("addon.jar");

View File

@ -55,7 +55,6 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.flags.Flag.Mode;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.Database;