@Test public void onQuit() { Timer timer = mock(Timer.class); GameOptions gameOptions = mock(GameOptions.class); Broadcast broadcast = mock(Broadcast.class); Server server = mock(Server.class); when(gameOptions.getMinimumPlayersToStart()).thenReturn(10); PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(mock(Player.class), ""); WaitingQuitListener waitingQuitListener = new WaitingQuitListener(timer, gameOptions, broadcast, server); setOnlinePlayers(server, 11); waitingQuitListener.onQuit(playerQuitEvent); verify(timer, times(0)).stop(); setOnlinePlayers(server, 9); waitingQuitListener.onQuit(playerQuitEvent); verify(timer, times(1)).stop(); }
@EventHandler public void onQuit(PlayerQuitEvent event) { if (server.getOnlinePlayers().size() < gameOptions.getMinimumPlayersToStart()) { gameStartingTimer.stop(); broadcast.broadcast(new Message("game.start.not_enough_players")); } }
WaitingQuitListener extends WaitingStateListener { @EventHandler public void onQuit(PlayerQuitEvent event) { if (server.getOnlinePlayers().size() < gameOptions.getMinimumPlayersToStart()) { gameStartingTimer.stop(); broadcast.broadcast(new Message("game.start.not_enough_players")); } } }
WaitingQuitListener extends WaitingStateListener { @EventHandler public void onQuit(PlayerQuitEvent event) { if (server.getOnlinePlayers().size() < gameOptions.getMinimumPlayersToStart()) { gameStartingTimer.stop(); broadcast.broadcast(new Message("game.start.not_enough_players")); } }  }
WaitingQuitListener extends WaitingStateListener { @EventHandler public void onQuit(PlayerQuitEvent event) { if (server.getOnlinePlayers().size() < gameOptions.getMinimumPlayersToStart()) { gameStartingTimer.stop(); broadcast.broadcast(new Message("game.start.not_enough_players")); } }  @EventHandler void onQuit(PlayerQuitEvent event); }
WaitingQuitListener extends WaitingStateListener { @EventHandler public void onQuit(PlayerQuitEvent event) { if (server.getOnlinePlayers().size() < gameOptions.getMinimumPlayersToStart()) { gameStartingTimer.stop(); broadcast.broadcast(new Message("game.start.not_enough_players")); } }  @EventHandler void onQuit(PlayerQuitEvent event);  }