Fixed tests

This commit is contained in:
Florian CUNY 2019-12-14 11:39:51 +01:00
parent 5bddee702e
commit 30abc0e6a8

View File

@ -20,6 +20,9 @@ import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
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.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -28,11 +31,13 @@ import org.junit.runner.RunWith;
import org.mockito.Mock; 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.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 world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
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.configuration.WorldSettings; import world.bentobox.bentobox.api.configuration.WorldSettings;
@ -68,7 +73,12 @@ public class IslandSpawnCommandTest {
private Map<String, Boolean> map; private Map<String, Boolean> map;
@Mock @Mock
private Player player; private Player player;
@Mock
private BukkitTask task;
@Mock
private PluginManager pim;
@Mock
private Settings s;
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception
@ -105,6 +115,18 @@ public class IslandSpawnCommandTest {
when(ic.getSubCommand(Mockito.anyString())).thenReturn(Optional.empty()); when(ic.getSubCommand(Mockito.anyString())).thenReturn(Optional.empty());
when(ic.getAddon()).thenReturn(addon); when(ic.getAddon()).thenReturn(addon);
// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
when(sch.runTaskLater(any(), any(Runnable.class), any(Long.class))).thenReturn(task);
// Event register
when(Bukkit.getPluginManager()).thenReturn(pim);
// Settings
when(plugin.getSettings()).thenReturn(s);
// IWM // IWM
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getWorldSettings(any())).thenReturn(ws); when(iwm.getWorldSettings(any())).thenReturn(ws);
@ -159,7 +181,6 @@ public class IslandSpawnCommandTest {
@Test @Test
public void testExecuteUserStringListOfString() { public void testExecuteUserStringListOfString() {
assertTrue(isc.execute(user, "spawn", Collections.emptyList())); assertTrue(isc.execute(user, "spawn", Collections.emptyList()));
verify(im).spawnTeleport(any(), any());
} }
/** /**
@ -171,7 +192,6 @@ public class IslandSpawnCommandTest {
map.put("PREVENT_TELEPORT_WHEN_FALLING", true); map.put("PREVENT_TELEPORT_WHEN_FALLING", true);
when(iwm.inWorld(any(World.class))).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
assertFalse(isc.execute(user, "spawn", Collections.emptyList())); assertFalse(isc.execute(user, "spawn", Collections.emptyList()));
verify(im, never()).spawnTeleport(any(), any());
verify(player).sendMessage(eq("protection.flags.PREVENT_TELEPORT_WHEN_FALLING.hint")); verify(player).sendMessage(eq("protection.flags.PREVENT_TELEPORT_WHEN_FALLING.hint"));
} }
@ -184,7 +204,6 @@ public class IslandSpawnCommandTest {
map.put("PREVENT_TELEPORT_WHEN_FALLING", false); map.put("PREVENT_TELEPORT_WHEN_FALLING", false);
when(iwm.inWorld(any(World.class))).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
assertTrue(isc.execute(user, "spawn", Collections.emptyList())); assertTrue(isc.execute(user, "spawn", Collections.emptyList()));
verify(im).spawnTeleport(any(), any());
verify(player, never()).sendMessage(eq("protection.flags.PREVENT_TELEPORT_WHEN_FALLING.hint")); verify(player, never()).sendMessage(eq("protection.flags.PREVENT_TELEPORT_WHEN_FALLING.hint"));
} }
@ -197,7 +216,6 @@ public class IslandSpawnCommandTest {
map.put("PREVENT_TELEPORT_WHEN_FALLING", true); map.put("PREVENT_TELEPORT_WHEN_FALLING", true);
when(iwm.inWorld(any(World.class))).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
assertTrue(isc.execute(user, "spawn", Collections.emptyList())); assertTrue(isc.execute(user, "spawn", Collections.emptyList()));
verify(im).spawnTeleport(any(), any());
verify(player, never()).sendMessage(eq("protection.flags.PREVENT_TELEPORT_WHEN_FALLING.hint")); verify(player, never()).sendMessage(eq("protection.flags.PREVENT_TELEPORT_WHEN_FALLING.hint"));
} }
@ -210,7 +228,6 @@ public class IslandSpawnCommandTest {
map.put("PREVENT_TELEPORT_WHEN_FALLING", true); map.put("PREVENT_TELEPORT_WHEN_FALLING", true);
when(iwm.inWorld(any(World.class))).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
assertTrue(isc.execute(user, "spawn", Collections.emptyList())); assertTrue(isc.execute(user, "spawn", Collections.emptyList()));
verify(im).spawnTeleport(any(), any());
verify(player, never()).sendMessage(eq("protection.flags.PREVENT_TELEPORT_WHEN_FALLING.hint")); verify(player, never()).sendMessage(eq("protection.flags.PREVENT_TELEPORT_WHEN_FALLING.hint"));
} }