Search in sources :

Example 6 with BukkitTask

use of org.bukkit.scheduler.BukkitTask in project AuthMeReloaded by AuthMe.

the class LimboPlayerTaskManagerTest method shouldCancelExistingTimeoutTask.

@Test
public void shouldCancelExistingTimeoutTask() {
    // given
    Player player = mock(Player.class);
    LimboPlayer limboPlayer = new LimboPlayer(null, false, "", true, 0.3f, 0.1f);
    BukkitTask existingTask = mock(BukkitTask.class);
    limboPlayer.setTimeoutTask(existingTask);
    given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18);
    BukkitTask bukkitTask = mock(BukkitTask.class);
    given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
    // when
    limboPlayerTaskManager.registerTimeoutTask(player, limboPlayer);
    // then
    verify(existingTask).cancel();
    assertThat(limboPlayer.getTimeoutTask(), equalTo(bukkitTask));
    // 18 * TICKS_PER_SECOND
    verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L));
    verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
}
Also used : Player(org.bukkit.entity.Player) BukkitTask(org.bukkit.scheduler.BukkitTask) TimeoutTask(fr.xephi.authme.task.TimeoutTask) Test(org.junit.Test)

Example 7 with BukkitTask

use of org.bukkit.scheduler.BukkitTask in project AuthMeReloaded by AuthMe.

the class BukkitServiceTest method shouldRunTaskAsynchronously.

@Test
public void shouldRunTaskAsynchronously() {
    // given
    Runnable task = () -> {
    /* noop */
    };
    BukkitTask bukkitTask = mock(BukkitTask.class);
    given(scheduler.runTaskAsynchronously(authMe, task)).willReturn(bukkitTask);
    // when
    BukkitTask resultingTask = bukkitService.runTaskAsynchronously(task);
    // then
    assertThat(resultingTask, equalTo(bukkitTask));
    verify(scheduler, only()).runTaskAsynchronously(authMe, task);
}
Also used : BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Test(org.junit.Test)

Example 8 with BukkitTask

use of org.bukkit.scheduler.BukkitTask in project AuthMeReloaded by AuthMe.

the class BukkitServiceTest method shouldRunTask.

@Test
public void shouldRunTask() {
    // given
    Runnable task = () -> {
    /* noop */
    };
    BukkitTask bukkitTask = mock(BukkitTask.class);
    given(scheduler.runTask(authMe, task)).willReturn(bukkitTask);
    // when
    BukkitTask resultingTask = bukkitService.runTask(task);
    // then
    assertThat(resultingTask, equalTo(bukkitTask));
    verify(scheduler, only()).runTask(authMe, task);
}
Also used : BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Test(org.junit.Test)

Example 9 with BukkitTask

use of org.bukkit.scheduler.BukkitTask in project AuthMeReloaded by AuthMe.

the class BukkitServiceTest method shouldRunTaskTimer.

@Test
public void shouldRunTaskTimer() {
    // given
    BukkitRunnable bukkitRunnable = mock(BukkitRunnable.class);
    long delay = 20;
    long period = 80;
    BukkitTask bukkitTask = mock(BukkitTask.class);
    given(bukkitRunnable.runTaskTimer(authMe, delay, period)).willReturn(bukkitTask);
    // when
    BukkitTask result = bukkitService.runTaskTimer(bukkitRunnable, delay, period);
    // then
    assertThat(result, equalTo(bukkitTask));
    verify(bukkitRunnable).runTaskTimer(authMe, delay, period);
}
Also used : BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Test(org.junit.Test)

Aggregations

BukkitTask (org.bukkit.scheduler.BukkitTask)9 Test (org.junit.Test)7 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 TimeoutTask (fr.xephi.authme.task.TimeoutTask)3 Player (org.bukkit.entity.Player)2