@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 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 shouldReturnOneTableWhenOnlyOneMatchesAndClientAndTemplateAreSpecified()
      throws Exception {
    RandomTableGenerator generator = new RandomTableGenerator();
    generator.setGameTypes("BLACKJACK", "HISSTERIA", "ROULETTE");
    Set<Table> nonMatching = generator.generateTables(100);

    generator.setGameTypes(gameType);
    generator.setTemplateNames(toMap(gameType, variation));
    generator.setClients(toMap(gameType, clientId));
    generator.setFulls(false);
    generator.setShowInLobbys(true);
    generator.setAvailableForJoinings(true);
    generator.setStatii(TableStatus.open);

    GameStatus gameStatus = mock(GameStatus.class);
    when(gameRepository.getGameRules(anyString())).thenReturn(gameRules);
    when(gameRules.getJoiningDesirability(gameStatus)).thenReturn(45);

    Set<Table> matching = generator.generateTables(1);
    Table generatedTable = matching.iterator().next();
    generatedTable.setTableId(BigDecimal.valueOf(67));
    generatedTable.setCurrentGame(gameStatus);

    Set<Table> all = new HashSet<Table>(nonMatching);
    all.addAll(matching);
    gigaSpace.writeMultiple(all.toArray(new Table[all.size()]));

    assertEquals(101, gigaSpace.count(new Table()));

    Collection<TableSearchResult> found =
        tableSearchService.findTables(
            BigDecimal.TEN,
            new TableSearchCriteria(gameType, variation, clientId, Collections.<String>emptySet()));

    assertEquals(1, found.size());
    TableSearchResult table = found.iterator().next();
    assertEquals(BigDecimal.valueOf(67), table.getTableId());
    assertEquals(10, table.getSpareSeats());
    assertEquals(45, table.getJoiningDesirability());
  }
  @Test
  public void shouldReturnTableWhenPlayerIsNotPlayingAtOnlyTable() throws Exception {
    RandomTableGenerator generator = new RandomTableGenerator();
    generator.setGameTypes(gameType);
    generator.setTemplateNames(toMap(gameType, variation));
    generator.setClients(toMap(gameType, clientId));

    generator.setFulls(false);
    generator.setShowInLobbys(true);
    generator.setAvailableForJoinings(true);
    generator.setStatii(TableStatus.open);

    Set<Table> generated = generator.generateTables(1);

    GameStatus gameStatus = mock(GameStatus.class);
    when(gameRepository.getGameRules(anyString())).thenReturn(gameRules);
    when(gameRules.getJoiningDesirability(gameStatus)).thenReturn(45);

    Table first = generated.iterator().next();
    first.addPlayerToTable(new PlayerInformation(BigDecimal.ONE));
    first.setTableId(BigDecimal.valueOf(67));
    first.setCurrentGame(gameStatus);

    gigaSpace.writeMultiple(generated.toArray(new Table[generated.size()]));

    Collection<TableSearchResult> found =
        tableSearchService.findTables(
            BigDecimal.TEN,
            new TableSearchCriteria(gameType, variation, clientId, Collections.<String>emptySet()));
    assertEquals(1, found.size());
    TableSearchResult table = found.iterator().next();

    assertEquals(BigDecimal.valueOf(67), table.getTableId());
    assertEquals(10, table.getSpareSeats());
    assertEquals(10, table.getMaxSeats());
    assertEquals(45, table.getJoiningDesirability());
  }