Search in sources :

Example 1 with EntityEvent

use of org.bukkit.event.entity.EntityEvent in project AuthMeReloaded by AuthMe.

the class ListenerServiceTest method shouldAllowNpcPlayer.

@Test
public void shouldAllowNpcPlayer() {
    // given
    String playerName = "other_npc";
    Player player = mockPlayerWithName(playerName);
    EntityEvent event = mock(EntityEvent.class);
    given(event.getEntity()).willReturn(player);
    given(pluginHookService.isNpc(player)).willReturn(true);
    // when
    boolean result = listenerService.shouldCancelEvent(event);
    // then
    assertThat(result, equalTo(false));
    verify(pluginHookService).isNpc(player);
}
Also used : Player(org.bukkit.entity.Player) EntityEvent(org.bukkit.event.entity.EntityEvent) Test(org.junit.Test)

Example 2 with EntityEvent

use of org.bukkit.event.entity.EntityEvent in project AuthMeReloaded by AuthMe.

the class ListenerServiceTest method shouldHandleEntityEventWithNonPlayerEntity.

@Test
public void shouldHandleEntityEventWithNonPlayerEntity() {
    // given
    EntityEvent event = mock(EntityEvent.class);
    given(event.getEntity()).willReturn(mock(Entity.class));
    // when
    boolean result = listenerService.shouldCancelEvent(event);
    // then
    assertThat(result, equalTo(false));
}
Also used : Entity(org.bukkit.entity.Entity) EntityEvent(org.bukkit.event.entity.EntityEvent) Test(org.junit.Test)

Example 3 with EntityEvent

use of org.bukkit.event.entity.EntityEvent in project AuthMeReloaded by AuthMe.

the class ListenerServiceTest method shouldAllowUnrestrictedName.

@Test
public void shouldAllowUnrestrictedName() {
    // given
    String playerName = "Npc2";
    Player player = mockPlayerWithName(playerName);
    EntityEvent event = mock(EntityEvent.class);
    given(event.getEntity()).willReturn(player);
    given(validationService.isUnrestricted(playerName)).willReturn(true);
    // when
    boolean result = listenerService.shouldCancelEvent(event);
    // then
    assertThat(result, equalTo(false));
    verifyZeroInteractions(dataSource);
}
Also used : Player(org.bukkit.entity.Player) EntityEvent(org.bukkit.event.entity.EntityEvent) Test(org.junit.Test)

Example 4 with EntityEvent

use of org.bukkit.event.entity.EntityEvent in project AuthMeReloaded by AuthMe.

the class ListenerServiceTest method shouldAllowUnloggedPlayerForOptionalRegistration.

@Test
public void shouldAllowUnloggedPlayerForOptionalRegistration() {
    // given
    String playerName = "myPlayer1";
    Player player = mockPlayerWithName(playerName);
    given(playerCache.isAuthenticated(playerName)).willReturn(false);
    given(settings.getProperty(RegistrationSettings.FORCE)).willReturn(false);
    EntityEvent event = mock(EntityEvent.class);
    given(event.getEntity()).willReturn(player);
    listenerService.reload(settings);
    // when
    boolean result = listenerService.shouldCancelEvent(event);
    // then
    assertThat(result, equalTo(false));
    verify(playerCache).isAuthenticated(playerName);
    verify(dataSource).isAuthAvailable(playerName);
}
Also used : Player(org.bukkit.entity.Player) EntityEvent(org.bukkit.event.entity.EntityEvent) Test(org.junit.Test)

Example 5 with EntityEvent

use of org.bukkit.event.entity.EntityEvent in project AuthMeReloaded by AuthMe.

the class ListenerServiceTest method shouldHandleEventWithNullEntity.

@Test
public void shouldHandleEventWithNullEntity() {
    // given
    EntityEvent event = mock(EntityEvent.class);
    given(event.getEntity()).willReturn(null);
    // when
    boolean result = listenerService.shouldCancelEvent(event);
    // then
    assertThat(result, equalTo(false));
}
Also used : EntityEvent(org.bukkit.event.entity.EntityEvent) Test(org.junit.Test)

Aggregations

EntityEvent (org.bukkit.event.entity.EntityEvent)7 Test (org.junit.Test)7 Player (org.bukkit.entity.Player)5 Entity (org.bukkit.entity.Entity)1