Skip to content

Commit

Permalink
Notify client about ended games
Browse files Browse the repository at this point in the history
  • Loading branch information
micheljung committed Oct 17, 2018
1 parent 38c7ca6 commit 79e1399
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ private void onGameClosed(Game game) {
}

changeGameState(game, GameState.CLOSED);
markDirty(game, Duration.ZERO, Duration.ZERO);

activeGameRepository.delete(game);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ public void endGameIfNoPlayerConnected() throws Exception {
closePlayerGame(player2);
assertThat(game.getState(), is(GameState.CLOSED));

ArgumentCaptor<GameResponse> gameCaptor = ArgumentCaptor.forClass(GameResponse.class);
verify(clientService, atLeastOnce()).broadcastDelayed(gameCaptor.capture(), any(), any(), any(), any());

assertThat(gameCaptor.getValue().getState(), is(GameState.CLOSED));
assertThat(player1.getCurrentGame(), is(nullValue()));
assertThat(player1.getGameState(), is(PlayerGameState.NONE));
assertThat(player2.getCurrentGame(), is(nullValue()));
Expand All @@ -632,6 +636,11 @@ public void onGameClosedDoesntSaveGameIfGameDidntStart() throws Exception {
verifyZeroInteractions(divisionService);
assertThat(player1.getCurrentGame(), is(nullValue()));
assertThat(player1.getGameState(), is(PlayerGameState.NONE));

ArgumentCaptor<GameResponse> gameCaptor = ArgumentCaptor.forClass(GameResponse.class);
verify(clientService, atLeastOnce()).broadcastDelayed(gameCaptor.capture(), any(), any(), any(), any());

assertThat(gameCaptor.getValue().getState(), is(GameState.CLOSED));
}

@Test
Expand Down Expand Up @@ -718,6 +727,11 @@ public void onHostLeftClosesGameIfOpen() throws Exception {
assertThat(player1.getGameState(), is(PlayerGameState.NONE));
assertThat(player2.getCurrentGame(), is(nullValue()));
assertThat(player2.getGameState(), is(PlayerGameState.NONE));

ArgumentCaptor<GameResponse> gameCaptor = ArgumentCaptor.forClass(GameResponse.class);
verify(clientService, atLeastOnce()).broadcastDelayed(gameCaptor.capture(), any(), any(), any(), any());

assertThat(gameCaptor.getValue().getState(), is(GameState.CLOSED));
}

@Test
Expand Down

0 comments on commit 79e1399

Please sign in to comment.