### Question:
LimboPlayerTaskManager { void registerTimeoutTask(Player player, LimboPlayer limbo) { final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; if (timeout > 0) { String message = messages.retrieveSingle(player, MessageKey.LOGIN_TIMEOUT_ERROR); BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout); limbo.setTimeoutTask(task); } } LimboPlayerTaskManager();   }### Answer:
@Test public void shouldRegisterTimeoutTask() { Player player = mock(Player.class); LimboPlayer limboPlayer = mock(LimboPlayer.class); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(30); BukkitTask bukkitTask = mock(BukkitTask.class); given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask); limboPlayerTaskManager.registerTimeoutTask(player, limboPlayer); verify(limboPlayer).setTimeoutTask(bukkitTask); verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(600L)); verify(messages).retrieveSingle(player, MessageKey.LOGIN_TIMEOUT_ERROR); }
@Test public void shouldNotRegisterTimeoutTaskForZeroTimeout() { Player player = mock(Player.class); LimboPlayer limboPlayer = mock(LimboPlayer.class); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(0); limboPlayerTaskManager.registerTimeoutTask(player, limboPlayer); verifyZeroInteractions(limboPlayer, bukkitService); }
@Test public void shouldCancelExistingTimeoutTask() { Player player = mock(Player.class); LimboPlayer limboPlayer = new LimboPlayer(null, false, Collections.emptyList(), 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); limboPlayerTaskManager.registerTimeoutTask(player, limboPlayer); verify(existingTask).cancel(); assertThat(limboPlayer.getTimeoutTask(), equalTo(bukkitTask)); verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L)); verify(messages).retrieveSingle(player, MessageKey.LOGIN_TIMEOUT_ERROR); }