コード例 #1
0
 @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);
 }
コード例 #2
0
 @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);
 }
コード例 #3
0
 @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);
 }
コード例 #4
0
 @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);
 }
コード例 #5
0
  @Test
  public void testProcessTransactionResultUpdatesCachedBalance() {
    BigDecimal ORIGINAL_BALANCE = BigDecimal.ONE;
    BigDecimal NEW_BALANCE = BigDecimal.TEN;
    table.setCurrentGame(gameStatus);
    table.setGameId(GAME_ID);
    com.yazino.game.api.GamePlayer player =
        new com.yazino.game.api.GamePlayer(PLAYER1_ID, SESSION_ID, "");
    addPlayersToGame(gameStatus, player);
    table.playerWithAccountId(PLAYER1_ACCOUNT_ID).setCachedBalance(ORIGINAL_BALANCE);
    final com.yazino.game.api.TransactionResult txResult =
        new com.yazino.game.api.TransactionResult(
            "foo", true, null, PLAYER1_ACCOUNT_ID, NEW_BALANCE, null);
    host = gameHost(new InMemoryGameRepository(gameRules));

    // exercise SUT
    host.processTransactionResult(table, GAME_ID, txResult);

    // verify
    assertEquals(NEW_BALANCE, table.playerWithAccountId(PLAYER1_ACCOUNT_ID).getCachedBalance());
  }
コード例 #6
0
 @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();
 }