Search in sources :

Example 6 with EntityEvent

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

the class ListenerServiceTest method shouldAllowAuthenticatedPlayer.

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

Example 7 with EntityEvent

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

the class ListenerServiceTest method shouldDenyUnLoggedPlayer.

@Test
public void shouldDenyUnLoggedPlayer() {
    // given
    String playerName = "Tester";
    Player player = mockPlayerWithName(playerName);
    given(playerCache.isAuthenticated(playerName)).willReturn(false);
    EntityEvent event = mock(EntityEvent.class);
    given(event.getEntity()).willReturn(player);
    // when
    boolean result = listenerService.shouldCancelEvent(event);
    // then
    assertThat(result, equalTo(true));
    verify(playerCache).isAuthenticated(playerName);
    // makes sure the setting is checked first = avoid unnecessary DB operation
    verifyZeroInteractions(dataSource);
}
Also used : Player(org.bukkit.entity.Player) 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