private com.yazino.game.api.ObservableContext getContextFor( final com.yazino.game.api.GamePlayer player, boolean skipIfPossible, long startIncrement) { if (player == null) { return new com.yazino.game.api.ObservableContext(null, null); } final PlayerInformation playerInfo = table.playerAtTable(player.getId()); return playerInfo.toObservableContext(skipIfPossible, startIncrement); }
@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 executeAcknowledgement() { table.playerAcknowledgesIncrement(A_PLAYER.getId(), 1L); table.setIncrement(10L); table.setCurrentGame(gameStatus); when(gameRules.isAPlayer(gameStatus, A_PLAYER)).thenReturn(true); addPlayersToGame(gameStatus, A_PLAYER); command = new CommandWrapper( table.getTableId(), table.getGameId(), A_PLAYER.getId(), SESSION_ID, com.yazino.game.api.Command.CommandType.Ack.getCode(), "9"); command.setRequestId(UUID); executeCommand(); assertEquals(9L, table.playerAtTable(A_PLAYER.getId()).getAcknowledgedIncrement()); }
@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)); }
private void addPlayersToGame( com.yazino.game.api.GameStatus gameStatus, com.yazino.game.api.GamePlayer... players) { Collection<com.yazino.game.api.PlayerAtTableInformation> playerAtTableInformationCollection = new ArrayList<>(); for (com.yazino.game.api.GamePlayer player : players) { playerAtTableInformationCollection.add( new com.yazino.game.api.PlayerAtTableInformation( player, Collections.<String, String>emptyMap())); if (table.playerAtTable(player.getId()) == null) { if (player.getId().equals(PLAYER_ID)) { table.addPlayerToTable( new PlayerInformation( PLAYER_ID, PLAYER_NAME, PLAYER_ACCOUNT_ID, BigDecimal.TEN, BigDecimal.ZERO)); } else if (player.getId().equals(PLAYER1_ID)) { table.addPlayerToTable( new PlayerInformation( PLAYER1_ID, "player1", PLAYER1_ACCOUNT_ID, BigDecimal.TEN, BigDecimal.ZERO)); } else if (player.getId().equals(PLAYER2_ID)) { table.addPlayerToTable( new PlayerInformation( PLAYER2_ID, "player2", PLAYER2_ACCOUNT_ID, BigDecimal.TEN, BigDecimal.ZERO)); } else { table.addPlayerToTable( new PlayerInformation( player.getId(), player.getName(), player.getId(), BigDecimal.TEN, BigDecimal.ZERO)); } } } when(gameRules.getPlayerInformation(gameStatus)).thenReturn(playerAtTableInformationCollection); }
@Before public void setUp() throws com.yazino.game.api.GameException, WalletServiceException { MockitoAnnotations.initMocks(this); timeSource = new SettableTimeSource(System.currentTimeMillis()); command = new CommandWrapper(TABLE_ID, GAME_ID, A_PLAYER.getId(), SESSION_ID, "T"); command.setRequestId(UUID); playerStatisticEventsPublisher = new InMemoryPlayerStatisticEventsPublisher(); table = new Table( new com.yazino.game.api.GameType(GAME_TYPE, "Test", Collections.<String>emptySet()), BigDecimal.ONE, "test", true); table.setTableId(TABLE_ID); table.setTableStatus(TableStatus.open); table.setVariationProperties(new HashMap<String, String>()); when(bufferedGameHostWalletFactory.create(table.getTableId(), command.getRequestId())) .thenReturn(bufferedGameHostWallet); when(bufferedGameHostWalletFactory.create(table.getTableId())) .thenReturn(bufferedGameHostWallet); when(auditor.newLabel()).thenReturn(AUDIT_LABEL); when(bufferedGameHostWallet.getBalance(Mockito.isA(BigDecimal.class))) .thenReturn(BigDecimal.ZERO); when(uuidSource.getNewUUID()).thenReturn(NEW_UUID); when(auditor.newLabel()).thenReturn(AUDIT_LABEL); when(bufferedGameHostWallet.getBalance(Mockito.isA(BigDecimal.class))) .thenReturn(ACCOUNT_BALANCE); when(gameRules.getGameType()).thenReturn("TEST"); when(playerRepository.findSummaryByPlayerAndSession(PLAYER_ID, SESSION_ID)) .thenReturn( aPlayerSessionSummary(PLAYER_ID, "Player", PLAYER_ACCOUNT_ID, BigDecimal.valueOf(100))); when(playerRepository.findSummaryByPlayerAndSession(PLAYER_ID, null)) .thenReturn( aPlayerSessionSummary(PLAYER_ID, "Player", PLAYER_ACCOUNT_ID, BigDecimal.valueOf(100))); when(playerRepository.findSummaryByPlayerAndSession(PLAYER1_ID, null)) .thenReturn( aPlayerSessionSummary( PLAYER1_ID, "Player1", PLAYER1_ACCOUNT_ID, BigDecimal.valueOf(200))); when(playerRepository.findSummaryByPlayerAndSession(PLAYER2_ID, null)) .thenReturn( aPlayerSessionSummary( PLAYER2_ID, "Player2", PLAYER2_ACCOUNT_ID, BigDecimal.valueOf(300))); when(chatRepository.getOrCreateForLocation(TABLE_ID.toPlainString())) .thenReturn(new ChatChannel(TABLE_ID.toPlainString())); }