@Test
 public void statsDontGetPublishedToActivePlayersIfGameNotOver()
     throws com.yazino.game.api.GameException {
   whenGameStart();
   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, "");
   whenPlayers(p1, p2);
   when(gameRules.getObservableStatus(gameStatus1, getContextFor(p1)))
       .thenReturn(new PrintlnStatus());
   when(gameRules.getObservableStatus(gameStatus1, getContextFor(p2)))
       .thenReturn(new PrintlnStatus());
   when(gameRules.isComplete(gameStatus1)).thenReturn(false);
   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);
   executeCommand();
   verify(locationService, times(2))
       .notify(
           any(BigDecimal.class),
           any(BigDecimal.class),
           any(LocationChangeType.class),
           any(Location.class));
   verifyNoMoreInteractions(locationService);
 }
 @Test
 public void testProcessTransactionResultCorrectlyCallsAuditOnSuccessWithNonNullExecutionResult()
     throws com.yazino.game.api.GameException {
   final String auditLabel = "test424243542354";
   gameStatus = mock(com.yazino.game.api.GameStatus.class);
   when(gameRules.canBeClosed(gameStatus)).thenReturn(false);
   when(gameRules.isComplete(gameStatus)).thenReturn(false);
   whenPlayers();
   when(gameRules.getPlayerInformation(gameStatus))
       .thenReturn(Collections.<com.yazino.game.api.PlayerAtTableInformation>emptyList());
   when(gameRules.getNumberOfSeatsTaken(gameStatus)).thenReturn(0);
   table.setCurrentGame(gameStatus);
   table.setGameId(GAME_ID);
   final com.yazino.game.api.TransactionResult txResult =
       new com.yazino.game.api.TransactionResult("foo", true, null, null, null, null);
   final com.yazino.game.api.ExecutionResult executionResult =
       new com.yazino.game.api.ExecutionResult.Builder(gameRules, gameStatus).build();
   when(gameRules.processTransactionResult(
           isA(com.yazino.game.api.ExecutionContext.class), eq(txResult)))
       .thenReturn(executionResult);
   auditor = mock(Auditor.class);
   when(auditor.newLabel()).thenReturn(auditLabel);
   host = gameHost(new InMemoryGameRepository(gameRules));
   host.processTransactionResult(table, GAME_ID, txResult);
 }
 @Test
 public void testProcessTransactionResultCorrectlyCallsAuditOnSuccessWithNullExecutionResult() {
   final String auditLabel = "test424542542354";
   gameStatus = mock(com.yazino.game.api.GameStatus.class);
   when(gameRules.isComplete(gameStatus)).thenReturn(false);
   table.setCurrentGame(gameStatus);
   table.setGameId(GAME_ID);
   final com.yazino.game.api.TransactionResult txResult =
       new com.yazino.game.api.TransactionResult("foo", true, null, null, null, null);
   auditor = mock(Auditor.class);
   when(auditor.newLabel()).thenReturn(auditLabel);
   host = gameHost(new InMemoryGameRepository(gameRules));
   host.processTransactionResult(table, GAME_ID, txResult);
 }
 @Test
 public void testProcessTransactionResultIsNotProcessedForCompleteGame() {
   final GameRepository mockGameRepository = mock(GameRepository.class);
   when(mockGameRepository.getGameRules(GAME_TYPE)).thenReturn(gameRules);
   gameStatus = mock(com.yazino.game.api.GameStatus.class);
   when(gameRules.isComplete(gameStatus)).thenReturn(true);
   table.setCurrentGame(gameStatus);
   table.setGameId(GAME_ID);
   final com.yazino.game.api.TransactionResult txResult =
       new com.yazino.game.api.TransactionResult("foo", true, null, null, null, null);
   host = gameHost(mockGameRepository);
   host.processTransactionResult(table, GAME_ID, txResult);
   verifyNoMoreInteractions(documentDispatcher);
 }
  @Test
  public void shouldntRunPostProcessorsWhenDisabledAndNextGameCreated() {
    Table table = tableWithPhase(GameFinished, 6L);
    when(wallet.getTable()).thenReturn(table);
    GameInitialiser.GameInitialisationContext context = defaultEventContext();
    context.setAllowedToMoveToNextGame(true);
    context.setRunPostProcessors(false);
    when(gameRules.isComplete(table.getCurrentGame())).thenReturn(true);
    underTest.setPostInitialisationProcessors(toList(postprocessor));

    underTest.initialiseGame(context);

    assertEquals(Long.valueOf(7), table.getGameId());
    verifyZeroInteractions(postprocessor);
  }
 @Test
 public void testProcessTransactionResultIsOnlyExecutedForTheCurrentGame() {
   final GameRepository mockGameRepository = mock(GameRepository.class);
   when(mockGameRepository.getGameRules(GAME_TYPE)).thenReturn(gameRules);
   final long differentGameId = GAME_ID + 6;
   gameStatus = mock(com.yazino.game.api.GameStatus.class);
   when(gameRules.isComplete(gameStatus)).thenReturn(false);
   table.setCurrentGame(gameStatus);
   table.setGameId(GAME_ID);
   final com.yazino.game.api.TransactionResult txResult =
       new com.yazino.game.api.TransactionResult("foo", true, null, null, null, null);
   host = gameHost(mockGameRepository);
   host.processTransactionResult(table, differentGameId, txResult);
   verifyNoMoreInteractions(locationService);
 }
  @Test
  public void shouldIncrementGameIdWhenCreatedNextGameAndNotifyPostProcessors() {
    Table table = tableWithPhase(GameFinished, 6L);
    when(wallet.getTable()).thenReturn(table);
    GameInitialiser.GameInitialisationContext context = defaultEventContext();
    context.setAllowedToMoveToNextGame(true);
    when(gameRules.isComplete(table.getCurrentGame())).thenReturn(true);
    underTest.setPostInitialisationProcessors(toList(postprocessor));

    underTest.initialiseGame(context);

    assertEquals(Long.valueOf(7), table.getGameId());
    verify(postprocessor)
        .postProcess(
            any(com.yazino.game.api.ExecutionResult.class),
            any(com.yazino.game.api.Command.class),
            eq(table),
            anyString(),
            anyList(),
            eq(context.getPlayerId()));
  }
 @SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "ThrowableInstanceNeverThrown"})
 @Test
 public void testProcessTransactionResultCorrectlyCallsAuditOnFailure()
     throws com.yazino.game.api.GameException {
   final String auditLabel = "test42454254345345";
   gameStatus = mock(com.yazino.game.api.GameStatus.class);
   when(gameRules.isComplete(gameStatus)).thenReturn(false);
   table.setCurrentGame(gameStatus);
   table.setGameId(GAME_ID);
   final com.yazino.game.api.TransactionResult txResult =
       new com.yazino.game.api.TransactionResult("foo", true, null, null, null, null);
   final com.yazino.game.api.GameException thrownException =
       new com.yazino.game.api.GameException(
           new com.yazino.game.api.ParameterisedMessage("test.mock.error"));
   when(gameRules.processTransactionResult(
           isA(com.yazino.game.api.ExecutionContext.class), eq(txResult)))
       .thenThrow(thrownException);
   auditor = mock(Auditor.class);
   when(auditor.newLabel()).thenReturn(auditLabel);
   host = gameHost(new InMemoryGameRepository(gameRules));
   host.processTransactionResult(table, GAME_ID, txResult);
   verify(auditor, times(1)).newLabel();
 }