2022-03-28 18:04:15 +02:00
|
|
|
package world.bentobox.limits.commands.player;
|
2020-01-09 00:12:24 +01:00
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Ignore;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.mockito.Mock;
|
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
|
|
import org.powermock.modules.junit4.PowerMockRunner;
|
|
|
|
|
|
|
|
import world.bentobox.bentobox.BentoBox;
|
|
|
|
import world.bentobox.bentobox.database.objects.Island;
|
|
|
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
|
|
|
import world.bentobox.limits.Limits;
|
2020-09-08 00:05:51 +02:00
|
|
|
import world.bentobox.limits.Settings;
|
|
|
|
import world.bentobox.limits.objects.IslandBlockCount;
|
2020-01-09 00:12:24 +01:00
|
|
|
|
|
|
|
@RunWith(PowerMockRunner.class)
|
|
|
|
@PrepareForTest( Bukkit.class )
|
2020-09-08 00:05:51 +02:00
|
|
|
public class LimitTabTest {
|
2020-01-09 00:12:24 +01:00
|
|
|
|
|
|
|
@Mock
|
|
|
|
private Limits addon;
|
2020-09-08 00:05:51 +02:00
|
|
|
|
|
|
|
private LimitTab lp;
|
2020-01-09 00:12:24 +01:00
|
|
|
|
|
|
|
@Mock
|
|
|
|
private Island island;
|
|
|
|
@Mock
|
|
|
|
private World world;
|
|
|
|
@Mock
|
|
|
|
private World nether;
|
|
|
|
@Mock
|
|
|
|
private World end;
|
|
|
|
@Mock
|
|
|
|
private BentoBox plugin;
|
2020-09-08 00:05:51 +02:00
|
|
|
@Mock
|
2020-01-09 00:12:24 +01:00
|
|
|
private IslandWorldManager iwm;
|
2020-09-08 00:05:51 +02:00
|
|
|
@Mock
|
|
|
|
private Settings settings;
|
2020-01-09 00:12:24 +01:00
|
|
|
|
|
|
|
@Before
|
2021-12-22 23:37:10 +01:00
|
|
|
public void setUp() {
|
2020-01-09 00:12:24 +01:00
|
|
|
// Island
|
|
|
|
when(island.getWorld()).thenReturn(world);
|
|
|
|
// Addon
|
|
|
|
when(addon.getPlugin()).thenReturn(plugin);
|
2020-09-08 00:05:51 +02:00
|
|
|
when(addon.getSettings()).thenReturn(settings);
|
|
|
|
when(settings.getLimits()).thenReturn(Collections.emptyMap());
|
2020-01-09 00:12:24 +01:00
|
|
|
when(plugin.getIWM()).thenReturn(iwm);
|
|
|
|
when(iwm.isNetherIslands(any())).thenReturn(true);
|
|
|
|
when(iwm.isEndIslands(any())).thenReturn(true);
|
|
|
|
when(iwm.getNetherWorld(eq(world))).thenReturn(nether);
|
|
|
|
when(iwm.getEndWorld(eq(world))).thenReturn(end);
|
2020-09-08 00:05:51 +02:00
|
|
|
// Worlds
|
2020-01-09 00:12:24 +01:00
|
|
|
Entity entity = mock(Entity.class);
|
|
|
|
when(entity.getType()).thenReturn(EntityType.BAT);
|
|
|
|
when(entity.getLocation()).thenReturn(mock(Location.class));
|
|
|
|
when(world.getEntities()).thenReturn(Collections.singletonList(entity));
|
|
|
|
when(nether.getEntities()).thenReturn(Collections.singletonList(entity));
|
|
|
|
when(end.getEntities()).thenReturn(Collections.singletonList(entity));
|
2021-09-07 02:14:06 +02:00
|
|
|
lp = new LimitTab(addon, new IslandBlockCount("", ""), Collections.emptyMap(), island, world, null, LimitTab.SORT_BY.A2Z);
|
2020-01-09 00:12:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
2021-12-22 23:37:10 +01:00
|
|
|
public void tearDown() {
|
2020-01-09 00:12:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Ignore
|
|
|
|
public void testShowLimits() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetCountInIslandSpace() {
|
|
|
|
when(island.inIslandSpace(any(Location.class))).thenReturn(true);
|
|
|
|
EntityType ent = EntityType.BAT;
|
|
|
|
assertEquals(3L, lp.getCount(island, ent));
|
|
|
|
ent = EntityType.GHAST;
|
|
|
|
assertEquals(0L, lp.getCount(island, ent));
|
|
|
|
when(iwm.isEndIslands(any())).thenReturn(false);
|
|
|
|
ent = EntityType.BAT;
|
|
|
|
assertEquals(2L, lp.getCount(island, ent));
|
|
|
|
when(iwm.isNetherIslands(any())).thenReturn(false);
|
|
|
|
ent = EntityType.BAT;
|
|
|
|
assertEquals(1L, lp.getCount(island, ent));
|
|
|
|
}
|
2020-09-08 00:05:51 +02:00
|
|
|
|
2020-01-09 00:12:24 +01:00
|
|
|
@Test
|
|
|
|
public void testGetCountNotInIslandSpace() {
|
|
|
|
EntityType ent = EntityType.BAT;
|
|
|
|
assertEquals(0L, lp.getCount(island, ent));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|