@Test
  public void shutdownIgnoresTablesWithNullGames() {
    table.setCurrentGame(null);

    List<HostDocument> result = gameHost(gameRules).shutdown(table);
    assertEquals(0, result.size());
  }
  @Test
  public void testPlayersGetNewStatus() throws com.yazino.game.api.GameException {
    whenGameStart();
    command = commandFrom(PLAYER1_ID);
    com.yazino.game.api.GamePlayer p1 =
        new com.yazino.game.api.GamePlayer(PLAYER1_ID, SESSION_ID, "");
    com.yazino.game.api.GamePlayer p2 =
        new com.yazino.game.api.GamePlayer(PLAYER2_ID, SESSION_ID, "");
    table.setCurrentGame(gameStatus1);
    whenPlayers(p1, p2);
    when(gameRules.getObservableStatus(gameStatus1, getContextFor(p1, false, table.getIncrement())))
        .thenReturn(new PrintlnStatus());
    when(gameRules.getObservableStatus(gameStatus1, getContextFor(p2, true, table.getIncrement())))
        .thenReturn(new PrintlnStatus());
    final com.yazino.game.api.ExecutionResult result =
        new com.yazino.game.api.ExecutionResult.Builder(gameRules, gameStatus1)
            .scheduledEvents(emptyEvents)
            .build();
    when(gameRules.execute(
            isA(com.yazino.game.api.ExecutionContext.class), eq(command.toCommand(PLAYER_NAME))))
        .thenReturn(result);
    final List<HostDocument> hostDocuments = executeCommand();

    // table.lastGameChanges?
    assertThat(hostDocuments.size(), is(equalTo(2)));
    assertThat(
        (GameStatusHostDocument) hostDocuments.get(0), Matchers.isA(GameStatusHostDocument.class));
    assertThat(
        (GameStatusHostDocument) hostDocuments.get(1), Matchers.isA(GameStatusHostDocument.class));
  }
 @Test
 public void testGetStatusSendsStatusToPlayer() {
   whenGameStart();
   command =
       new CommandWrapper(TABLE_ID, GAME_ID, A_PLAYER.getId(), SESSION_ID, "InitialGetStatus");
   command.setRequestId(UUID);
   final List<HostDocument> hostDocuments = executeCommand();
   assertThat(
       (GameStatusHostDocument) hostDocuments.get(0), Matchers.isA(GameStatusHostDocument.class));
 }
 @SuppressWarnings({"ThrowableInstanceNeverThrown"})
 @Test
 public void senderGetsErrorMessageWhenExceptionThrownInGameHost()
     throws com.yazino.game.api.GameException {
   whenGameStart();
   com.yazino.game.api.ParameterisedMessage pm =
       new com.yazino.game.api.ParameterisedMessage("UPS!");
   when(gameRules.execute(
           isA(com.yazino.game.api.ExecutionContext.class), eq(command.toCommand(PLAYER_NAME))))
       .thenThrow(new com.yazino.game.api.GameException(pm));
   final List<HostDocument> hostDocuments = executeCommand();
   assertThat((ErrorHostDocument) hostDocuments.get(1), Matchers.isA(ErrorHostDocument.class));
 }
 @Test
 public void tournamentTableShouldNotRetrievePlayersMainAccount() {
   table.setShowInLobby(false);
   table.setGameId(1l);
   host = gameHost(new InMemoryGameRepository(gameRules));
   BigDecimal playerId = BigDecimal.valueOf(54321);
   CommandWrapper aCommand =
       new CommandWrapper(table.getTableId(), 1l, playerId, SESSION_ID, "aCommand");
   aCommand.setRequestId(UUID);
   when(playerRepository.findSummaryByPlayerAndSession(playerId, SESSION_ID))
       .thenReturn(
           aPlayerSessionSummary(playerId, "", BigDecimal.valueOf(10), BigDecimal.valueOf(100)));
   List<HostDocument> documents = host.execute(table, aCommand);
   assertEquals(1, documents.size());
   assertThat((ErrorHostDocument) documents.get(0), Matchers.isA(ErrorHostDocument.class));
 }
 @Test
 public void shutdownReturnsInvestedAmountsOnlyOnceForPlayer() throws WalletServiceException {
   com.yazino.game.api.GamePlayer player1 =
       new com.yazino.game.api.GamePlayer(BigDecimal.valueOf(1), null, "p1");
   com.yazino.game.api.PlayerAtTableInformation p1 =
       new com.yazino.game.api.PlayerAtTableInformation(
           player1, BigDecimal.valueOf(10), Collections.<String, String>emptyMap());
   PlayerInformation pi1 =
       new PlayerInformation(
           player1.getId(),
           player1.getName(),
           BigDecimal.valueOf(501),
           BigDecimal.TEN,
           BigDecimal.valueOf(0));
   com.yazino.game.api.PlayerAtTableInformation p2 =
       new com.yazino.game.api.PlayerAtTableInformation(
           player1, BigDecimal.valueOf(15), Collections.<String, String>emptyMap());
   PlayerInformation pi2 =
       new PlayerInformation(
           player1.getId(),
           player1.getName(),
           BigDecimal.valueOf(501),
           BigDecimal.TEN,
           BigDecimal.valueOf(0));
   table.addPlayerToTable(pi1);
   table.addPlayerToTable(pi2);
   Collection<com.yazino.game.api.PlayerAtTableInformation> players = Arrays.asList(p1, p2);
   when(gameRules.getPlayerInformation(gameStatus)).thenReturn(players);
   table.setCurrentGame(gameStatus);
   List<HostDocument> documents = gameHost(gameRules).shutdown(table);
   assertEquals(1, documents.size());
   verify(bufferedGameHostWallet)
       .post(
           table.getTableId(),
           table.getGameId(),
           pi1,
           BigDecimal.valueOf(25),
           com.yazino.game.api.TransactionType.Return,
           AUDIT_LABEL,
           "Shutdown refund",
           NEW_UUID);
   verify(bufferedGameHostWallet).flush();
   verifyNoMoreInteractions(bufferedGameHostWallet);
 }
 @Test
 public void testObserversGetNotified() throws com.yazino.game.api.GameException {
   whenGameStart();
   final com.yazino.game.api.ExecutionResult executionResult =
       new com.yazino.game.api.ExecutionResult.Builder(
               new PrintlnRules(), new GameStatus(new PrintlnStatus()))
           .scheduledEvents(emptyEvents)
           .build();
   when(gameRules.getObservableStatus(gameStatus1, getContextFor(null)))
       .thenReturn(new PrintlnStatus());
   when(gameRules.execute(
           isA(com.yazino.game.api.ExecutionContext.class), eq(command.toCommand(PLAYER_NAME))))
       .thenReturn(executionResult);
   final List<HostDocument> hostDocuments = executeCommand();
   assertThat(
       (GameStatusHostDocument) hostDocuments.get(0), Matchers.isA(GameStatusHostDocument.class));
   assertThat(
       (GameStatusHostDocument) hostDocuments.get(1), Matchers.isA(GameStatusHostDocument.class));
 }
 @Test
 public void shutdownIgnoresNullInvestedAmounts() {
   com.yazino.game.api.PlayerAtTableInformation p1 =
       new com.yazino.game.api.PlayerAtTableInformation(
           new com.yazino.game.api.GamePlayer(BigDecimal.valueOf(1), SESSION_ID, "p1"),
           null,
           Collections.<String, String>emptyMap());
   PlayerInformation pi1 =
       new PlayerInformation(
           BigDecimal.valueOf(1),
           "p1",
           BigDecimal.valueOf(501),
           BigDecimal.TEN,
           BigDecimal.valueOf(0));
   table.addPlayerToTable(pi1);
   Collection<com.yazino.game.api.PlayerAtTableInformation> players = Arrays.asList(p1);
   when(gameRules.getPlayerInformation(gameStatus)).thenReturn(players);
   table.setCurrentGame(gameStatus);
   List<HostDocument> documents = gameHost(gameRules).shutdown(table);
   assertEquals(1, documents.size());
   verify(bufferedGameHostWallet).flush();
   verifyNoMoreInteractions(bufferedGameHostWallet);
 }