-
-
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.
Merge pull request #2508 from BentoBoxWorld/2507_Allow_creepers_to_hu…
…rt_but_not_destroy_blocks Change how creeper damage flag works. #2507
- Loading branch information
Showing
5 changed files
with
197 additions
and
31 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
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
136 changes: 136 additions & 0 deletions
136
src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CreeperListenerTest.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,136 @@ | ||
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.Bukkit; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Creeper; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.event.entity.EntityExplodeEvent; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import world.bentobox.bentobox.BentoBox; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup; | ||
import world.bentobox.bentobox.lists.Flags; | ||
import world.bentobox.bentobox.util.Util; | ||
|
||
/** | ||
* | ||
*/ | ||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest({ Bukkit.class, BentoBox.class, Flags.class, Util.class }) | ||
public class CreeperListenerTest extends AbstractCommonSetup { | ||
|
||
private CreeperListener cl; | ||
|
||
/** | ||
* @throws java.lang.Exception | ||
*/ | ||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
|
||
cl = new CreeperListener(); | ||
} | ||
|
||
/** | ||
* @throws java.lang.Exception | ||
*/ | ||
@After | ||
public void tearDown() throws Exception { | ||
User.clearUsers(); | ||
Mockito.framework().clearInlineMocks(); | ||
} | ||
|
||
/** | ||
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.CreeperListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}. | ||
*/ | ||
@Test | ||
public void testOnExplosionNotCreeper() { | ||
List<Block> list = new ArrayList<>(); | ||
Entity entity = mock(Entity.class); | ||
when(entity.getType()).thenReturn(EntityType.TNT); | ||
when(iwm.inWorld(location)).thenReturn(true); | ||
EntityExplodeEvent event = new EntityExplodeEvent(entity, location, list, 0); | ||
cl.onExplosion(event); | ||
assertFalse(event.isCancelled()); | ||
} | ||
|
||
/** | ||
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.CreeperListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}. | ||
*/ | ||
@Test | ||
public void testOnExplosionNotInWorld() { | ||
List<Block> list = new ArrayList<>(); | ||
Entity entity = mock(Entity.class); | ||
when(entity.getLocation()).thenReturn(location); | ||
when(entity.getType()).thenReturn(EntityType.CREEPER); | ||
when(iwm.inWorld(location)).thenReturn(false); | ||
EntityExplodeEvent event = new EntityExplodeEvent(entity, location, list, 0); | ||
cl.onExplosion(event); | ||
assertFalse(event.isCancelled()); | ||
} | ||
|
||
/** | ||
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.CreeperListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}. | ||
*/ | ||
@Test | ||
public void testOnExplosionCreeperInWorldDamageOK() { | ||
List<Block> list = new ArrayList<>(); | ||
list.add(mock(Block.class)); | ||
list.add(mock(Block.class)); | ||
list.add(mock(Block.class)); | ||
Creeper entity = mock(Creeper.class); | ||
when(entity.getLocation()).thenReturn(location); | ||
when(entity.getType()).thenReturn(EntityType.CREEPER); | ||
when(iwm.inWorld(location)).thenReturn(true); | ||
EntityExplodeEvent event = new EntityExplodeEvent(entity, location, list, 0); | ||
cl.onExplosion(event); | ||
assertFalse(event.isCancelled()); | ||
assertFalse(event.blockList().isEmpty()); // No clearing of block list | ||
} | ||
|
||
/** | ||
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.CreeperListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}. | ||
*/ | ||
@Test | ||
public void testOnExplosionCreeperInWorldDamageNOK() { | ||
Flags.CREEPER_DAMAGE.setSetting(world, false); | ||
List<Block> list = new ArrayList<>(); | ||
list.add(mock(Block.class)); | ||
list.add(mock(Block.class)); | ||
list.add(mock(Block.class)); | ||
Creeper entity = mock(Creeper.class); | ||
when(location.getWorld()).thenReturn(world); | ||
when(entity.getLocation()).thenReturn(location); | ||
when(entity.getType()).thenReturn(EntityType.CREEPER); | ||
when(iwm.inWorld(location)).thenReturn(true); | ||
EntityExplodeEvent event = new EntityExplodeEvent(entity, location, list, 0); | ||
cl.onExplosion(event); | ||
assertFalse(event.isCancelled()); | ||
assertTrue(event.blockList().isEmpty()); // No clearing of block list | ||
} | ||
|
||
/** | ||
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.CreeperListener#onPlayerInteractEntity(org.bukkit.event.player.PlayerInteractEntityEvent)}. | ||
*/ | ||
@Test | ||
public void testOnPlayerInteractEntity() { | ||
//TODO | ||
} | ||
|
||
} |
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