Skip to content

Entities

In Spigot and all derivative forks, Entity is the parent class of all animals, mobs and several more things. Therefore it's a common abstraction used in a lot of code. We added several Methods to our EntityMock implementation that will make testing much easier.

As Entity also implements MessageTarget, you can also use the methods provided there

Asserting Location

Oftentimes you want to check the Location of an entity. To simply this, Mockbukkit provides the EntityMock.assertLocation(Location,double) method. It allows you to check if the entity is within a given range around the specified Location

java
@Test
void test_AssertLocation() {
    //Assumes you already have entity instance
    entity.assertLocation(new Location(entity.getWorld(),0,0,0),2);
}
kotlin
@Test
fun test_AssertLocation() {
    //Assumes you already have entity instance
    entity.assertLocation(Location(entity.getWorld(),0,0,0),2)
}

Assert teleported

You can also assert a player has been teleported by a Plugin

java
@Test
void test_assertTeleported() {
    //Assumes you already have entity instance
    entity.assertTeleported(location, distance);
}
@Test
void test_assertTeleported() {
    //Assumes you already have entity instance
    entity.assertNotTeleported();
}
kotlin
@Test
fun test_assertTeleported() {
    //Assumes you already have entity instance
    entity.assertTeleported(location, distance)
}
@Test
fun test_assertTeleported() {
    //Assumes you already have entity instance
    entity.assertNotTeleported()
}

If you want to reset the teleported flag, just call the EntityMock.clearTeleported() method

In Bukkit, the only way to move a Entity is by teleporting it. As this might interfere with tests, we added theEntityMock.setLocation(location) method to move an entity without changing the teleported flag

Rename an Entity

In Mockbukkit you can also rename the entity to your hearts content

java
entity.setName("new-name");
kotlin
entity.setName("new-name")

Released under the MIT License.