@Test public void forceNewGameWillRestartTableAndStartNewGame() { Map<BigDecimal, BigDecimal> playerIdToAccountIdOverrides = new HashMap<>(); playerIdToAccountIdOverrides.put(PLAYER_ID, BigDecimal.valueOf(202020)); com.yazino.game.api.GameStatus status = new GameStatus(new PrintlnStatus()); com.yazino.game.api.ExecutionResult result = new com.yazino.game.api.ExecutionResult.Builder(gameRules, status).build(); when(gameRules.startNewGame(isA(com.yazino.game.api.GameCreationContext.class))) .thenReturn(result); when(auditor.newLabel()).thenReturn("X"); host = gameHost(new InMemoryGameRepository(gameRules)); table.setTableStatus(TableStatus.closed); table.setCurrentGame(null); Collection<com.yazino.game.api.PlayerAtTableInformation> playersAtTable = Arrays.asList( new com.yazino.game.api.PlayerAtTableInformation( new com.yazino.game.api.GamePlayer(PLAYER1_ID, null, "One"), Collections.<String, String>emptyMap()), new com.yazino.game.api.PlayerAtTableInformation( new com.yazino.game.api.GamePlayer(PLAYER2_ID, null, "Two"), Collections.<String, String>emptyMap())); host.forceNewGame(table, playersAtTable, playerIdToAccountIdOverrides); ArgumentCaptor<com.yazino.game.api.GameCreationContext> contextCaptor = ArgumentCaptor.forClass(com.yazino.game.api.GameCreationContext.class); verify(gameRules).startNewGame(contextCaptor.capture()); assertEquals(TableStatus.open, table.getTableStatus()); assertEquals(status, table.getCurrentGame()); assertEquals(playersAtTable, contextCaptor.getValue().getPlayersAtTableInformation()); }
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); }
@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 errorResponseThrowsHttpError() throws Exception { given(connection.getURL()).willReturn(new URL(URL)); given(connection.getResponseCode()).willReturn(400); Map<String, List<String>> responseHeaderFields = new LinkedHashMap<String, List<String>>(); given(connection.getHeaderFields()) .willReturn(responseHeaderFields, Collections.<String, List<String>>emptyMap()); Request request = new Request("GET", URL, Collections.<Header>emptyList(), null); Response response = underTest.execute(request); assertThat(response.getStatus()).isEqualTo(400); }
@Test public void postAndGet() throws Exception { given(connection.getURL()).willReturn(new URL(URL), new URL(URL + "/secret")); given(connection.getResponseCode()).willReturn(302, 200); Map<String, List<String>> responseHeaderFields = new LinkedHashMap<String, List<String>>(); responseHeaderFields.put("Location", Arrays.asList("http://example.com/secret")); given(connection.getHeaderFields()) .willReturn(responseHeaderFields, Collections.<String, List<String>>emptyMap()); Request request = new Request("POST", URL, Collections.<Header>emptyList(), null); Response response = underTest.execute(request); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getUrl()).isEqualTo(URL + "/secret"); }
@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); }