-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check passengers of jockeys when spawned. #2195
- Loading branch information
1 parent
6d2f798
commit 7fbd041
Showing
2 changed files
with
136 additions
and
1 deletion.
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
126 changes: 126 additions & 0 deletions
126
...est/java/world/bentobox/bentobox/listeners/flags/worldsettings/LimitMobsListenerTest.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,126 @@ | ||
package world.bentobox.bentobox.listeners.flags.worldsettings; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.event.entity.CreatureSpawnEvent; | ||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; | ||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
import org.powermock.reflect.Whitebox; | ||
|
||
import world.bentobox.bentobox.BentoBox; | ||
import world.bentobox.bentobox.managers.IslandWorldManager; | ||
|
||
/** | ||
* @author tastybento | ||
* | ||
*/ | ||
@RunWith(PowerMockRunner.class) | ||
public class LimitMobsListenerTest { | ||
|
||
@Mock | ||
private IslandWorldManager iwm; | ||
@Mock | ||
private @NonNull World world; | ||
private List<String> list = new ArrayList<>(); | ||
private LimitMobsListener lml; | ||
@Mock | ||
private LivingEntity zombie; | ||
@Mock | ||
private LivingEntity skelly; | ||
@Mock | ||
private LivingEntity jockey; | ||
@Mock | ||
private Location location; | ||
|
||
/** | ||
* @throws java.lang.Exception | ||
*/ | ||
@Before | ||
public void setUp() throws Exception { | ||
// Set up plugin | ||
BentoBox plugin = mock(BentoBox.class); | ||
Whitebox.setInternalState(BentoBox.class, "instance", plugin); | ||
when(plugin.getIWM()).thenReturn(iwm); | ||
list.add("SKELETON"); | ||
when(iwm.getMobLimitSettings(world)).thenReturn(list); | ||
when(iwm.inWorld(world)).thenReturn(true); | ||
when(iwm.inWorld(location)).thenReturn(true); | ||
when(location.getWorld()).thenReturn(world); | ||
when(zombie.getType()).thenReturn(EntityType.ZOMBIE); | ||
when(zombie.getLocation()).thenReturn(location); | ||
when(skelly.getType()).thenReturn(EntityType.SKELETON); | ||
when(skelly.getLocation()).thenReturn(location); | ||
when(jockey.getType()).thenReturn(EntityType.SPIDER); | ||
when(jockey.getLocation()).thenReturn(location); | ||
when(jockey.getPassengers()).thenReturn(List.of(skelly)); | ||
|
||
lml = new LimitMobsListener(); | ||
} | ||
|
||
/** | ||
* @throws java.lang.Exception | ||
*/ | ||
@After | ||
public void tearDown() throws Exception { | ||
Mockito.framework().clearInlineMocks(); | ||
} | ||
|
||
/** | ||
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.LimitMobsListener#onMobSpawn(org.bukkit.event.entity.CreatureSpawnEvent)}. | ||
*/ | ||
@Test | ||
public void testOnMobSpawn() { | ||
CreatureSpawnEvent e = new CreatureSpawnEvent(skelly, SpawnReason.NATURAL); | ||
lml.onMobSpawn(e); | ||
assertTrue(e.isCancelled()); | ||
} | ||
|
||
/** | ||
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.LimitMobsListener#onMobSpawn(org.bukkit.event.entity.CreatureSpawnEvent)}. | ||
*/ | ||
@Test | ||
public void testOnMobSpawnNotInWorld() { | ||
when(location.getWorld()).thenReturn(mock(World.class)); | ||
CreatureSpawnEvent e = new CreatureSpawnEvent(skelly, SpawnReason.NATURAL); | ||
lml.onMobSpawn(e); | ||
assertFalse(e.isCancelled()); | ||
} | ||
|
||
/** | ||
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.LimitMobsListener#onMobSpawn(org.bukkit.event.entity.CreatureSpawnEvent)}. | ||
*/ | ||
@Test | ||
public void testOnMobSpawnOkayToSpawn() { | ||
CreatureSpawnEvent e = new CreatureSpawnEvent(zombie, SpawnReason.NATURAL); | ||
lml.onMobSpawn(e); | ||
assertFalse(e.isCancelled()); | ||
} | ||
|
||
/** | ||
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.LimitMobsListener#onMobSpawn(org.bukkit.event.entity.CreatureSpawnEvent)}. | ||
*/ | ||
@Test | ||
public void testOnMobSpawnJockey() { | ||
CreatureSpawnEvent e = new CreatureSpawnEvent(jockey, SpawnReason.JOCKEY); | ||
lml.onMobSpawn(e); | ||
assertTrue(e.isCancelled()); | ||
} | ||
|
||
} |