Fix PanelListenerManager tests.

Added JavaDoc and adjusted boolean method name.
This commit is contained in:
tastybento 2018-06-16 10:52:44 +09:00
parent 21601089f4
commit e5cfab50f7
3 changed files with 28 additions and 2 deletions

View File

@ -1485,10 +1485,17 @@ public class Settings implements DataObject, WorldSettings {
this.worldFlags = worldFlags; this.worldFlags = worldFlags;
} }
public boolean getClosePanelOnClickOutside() { /**
* @return whether panels should close when clicked outside or not
*/
public boolean isClosePanelOnClickOutside() {
return closePanelOnClickOutside; return closePanelOnClickOutside;
} }
/**
* Set panel close on click outside
* @param closePanelOnClickOutside
*/
public void setClosePanelOnClickOutside(boolean closePanelOnClickOutside) { public void setClosePanelOnClickOutside(boolean closePanelOnClickOutside) {
this.closePanelOnClickOutside = closePanelOnClickOutside; this.closePanelOnClickOutside = closePanelOnClickOutside;
} }

View File

@ -25,7 +25,7 @@ public class PanelListenerManager implements Listener {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(InventoryClickEvent event) { public void onInventoryClick(InventoryClickEvent event) {
// Close inventory if clicked outside and if setting is true // Close inventory if clicked outside and if setting is true
if (BSkyBlock.getInstance().getSettings().getClosePanelOnClickOutside() && event.getSlotType().equals(SlotType.OUTSIDE)) { if (BSkyBlock.getInstance().getSettings().isClosePanelOnClickOutside() && event.getSlotType().equals(SlotType.OUTSIDE)) {
event.getWhoClicked().closeInventory(); event.getWhoClicked().closeInventory();
return; return;
} }

View File

@ -14,6 +14,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryAction;
@ -25,19 +26,28 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.panels.Panel; import us.tastybento.bskyblock.api.panels.Panel;
import us.tastybento.bskyblock.api.panels.PanelItem; import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.PanelItem.ClickHandler; import us.tastybento.bskyblock.api.panels.PanelItem.ClickHandler;
import us.tastybento.bskyblock.api.panels.PanelListener; import us.tastybento.bskyblock.api.panels.PanelListener;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util;
/** /**
* Test class for PanelListenerManager.java * Test class for PanelListenerManager.java
* @author tastybento * @author tastybento
* *
*/ */
@RunWith(PowerMockRunner.class)
@PrepareForTest({BSkyBlock.class, Util.class, Bukkit.class })
public class PanelListenerManagerTest { public class PanelListenerManagerTest {
private Player player; private Player player;
@ -52,12 +62,21 @@ public class PanelListenerManagerTest {
private Inventory anotherInv; private Inventory anotherInv;
private PanelListener pl; private PanelListener pl;
private ClickHandler ch; private ClickHandler ch;
private Settings settings;
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception
*/ */
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// Set up plugin
BSkyBlock plugin = mock(BSkyBlock.class);
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
// Settings
settings = mock(Settings.class);
when(plugin.getSettings()).thenReturn(settings);
when(settings.isClosePanelOnClickOutside()).thenReturn(true);
uuid = UUID.randomUUID(); uuid = UUID.randomUUID();
player = mock(Player.class); player = mock(Player.class);
when(player.getUniqueId()).thenReturn(uuid); when(player.getUniqueId()).thenReturn(uuid);