-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Entity limits are now counted to include nether and end.
- Loading branch information
1 parent
25be7a3
commit f907784
Showing
3 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/test/java/world/bentobox/limits/commands/LimitPanelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package world.bentobox.limits.commands; | ||
|
||
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; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest( Bukkit.class ) | ||
public class LimitPanelTest { | ||
|
||
@Mock | ||
private Limits addon; | ||
|
||
private LimitPanel lp; | ||
|
||
@Mock | ||
private Island island; | ||
@Mock | ||
private World world; | ||
@Mock | ||
private World nether; | ||
@Mock | ||
private World end; | ||
@Mock | ||
private BentoBox plugin; | ||
@Mock | ||
private IslandWorldManager iwm; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
// Island | ||
when(island.getWorld()).thenReturn(world); | ||
// Addon | ||
when(addon.getPlugin()).thenReturn(plugin); | ||
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); | ||
// Worlds | ||
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)); | ||
lp = new LimitPanel(addon); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
|
||
@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)); | ||
} | ||
|
||
@Test | ||
public void testGetCountNotInIslandSpace() { | ||
EntityType ent = EntityType.BAT; | ||
assertEquals(0L, lp.getCount(island, ent)); | ||
} | ||
|
||
} |