use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method onGameLaunching.
@Test
public void onGameLaunching() throws Exception {
Game game = hostGame(player1);
instance.updatePlayerOption(player1, player1.getId(), OPTION_FACTION, 1);
instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player1);
assertThat(game.getState(), is(GameState.PLAYING));
assertThat(game.getStartTime(), is(lessThan(Instant.now().plusSeconds(1))));
assertThat(game.getStartTime(), is(greaterThan(Instant.now().minusSeconds(10))));
verify(entityManager).persist(game);
verify(clientService, atLeastOnce()).broadcastDelayed(any(GameResponse.class), any(), any(), any(), any());
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateGameValiditySinglePlayer.
@Test
public void updateGameValiditySinglePlayer() throws Exception {
Game game = hostGame(player1);
launchGame(game);
instance.updateGameValidity(game);
assertThat(game.getValidity(), is(Validity.SINGLE_PLAYER));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method simpleValidGameWithEnded.
@Test
public void simpleValidGameWithEnded() throws Exception {
Game game = hostGame(player1);
addPlayer(game, player2);
launchGame(game);
Stream.of(player1, player2).forEach(player -> {
instance.reportArmyOutcome(player, 1, Outcome.VICTORY);
instance.reportArmyScore(player, 1, 10);
instance.reportArmyOutcome(player, 2, Outcome.DEFEAT);
instance.reportArmyScore(player, 2, -1);
});
assertThat(game.getValidity(), is(Validity.VALID));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method disconnectFromGame.
/**
* Tests whether all but the affected player are informed to drop someone.
*/
@Test
@SuppressWarnings("unchecked")
public void disconnectFromGame() throws Exception {
Game game = hostGame(player1);
Player player3 = (Player) new Player().setId(3);
Player player4 = (Player) new Player().setId(4);
addPlayer(game, player2);
addPlayer(game, player3);
addPlayer(game, player4);
when(playerService.getOnlinePlayer(3)).thenReturn(Optional.of(player3));
instance.disconnectPlayerFromGame(player1, 3);
ArgumentCaptor<List<ConnectionAware>> captor = ArgumentCaptor.forClass((Class) List.class);
verify(clientService).disconnectPlayerFromGame(eq(3), captor.capture());
List<ConnectionAware> recipients = captor.getValue();
assertThat(recipients, hasSize(3));
assertThat(recipients, hasItems(player1, player2, player4));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method onGameClosedSavesGameIfGameStarted.
@Test
public void onGameClosedSavesGameIfGameStarted() throws Exception {
Game game = hostGame(player1);
launchGame(game);
instance.updatePlayerGameState(PlayerGameState.CLOSED, player1);
assertThat(game.getState(), is(GameState.CLOSED));
verify(gameRepository).save(game);
verify(mapService).incrementTimesPlayed(game.getMapVersion().getMap());
verifyZeroInteractions(divisionService);
assertThat(player1.getCurrentGame(), is(nullValue()));
assertThat(player1.getGameState(), is(PlayerGameState.NONE));
}
Aggregations