@Test
  public void anAddedTagSendsAPlayerEvent() {
    final Player player = playerWithTags();
    when(playerRepository.findById(PLAYER_ID)).thenReturn(player);
    when(playerRepository.lock(PLAYER_ID)).thenReturn(player);

    underTest.processRequest(new PlayerTaggingRequest(PLAYER_ID, "abc", ADD));

    verify(playerEventService).send(anEventWithTags("abc"));
  }
  @Test
  public void anAddedTagIsSaved() {
    final Player player = playerWithTags();
    when(playerRepository.findById(PLAYER_ID)).thenReturn(player);
    when(playerRepository.lock(PLAYER_ID)).thenReturn(player);

    underTest.processRequest(new PlayerTaggingRequest(PLAYER_ID, "abc", ADD));

    verify(playerRepository).save(playerWithTags("abc"));
  }
  @Test
  public void aTagCanBeRemoved() {
    final Player player = playerWithTags("abc");
    when(playerRepository.findById(PLAYER_ID)).thenReturn(player);
    when(playerRepository.lock(PLAYER_ID)).thenReturn(player);

    underTest.processRequest(new PlayerTaggingRequest(PLAYER_ID, "abc", REMOVE));

    verify(playerRepository).save(playerWithTags());
  }
  @Test
  public void removingANonExistentTagIsIgnored() {
    final Player player = playerWithTags();
    when(playerRepository.findById(PLAYER_ID)).thenReturn(player);
    when(playerRepository.lock(PLAYER_ID)).thenReturn(player);

    underTest.processRequest(new PlayerTaggingRequest(PLAYER_ID, "abc", REMOVE));

    verify(playerRepository, never()).save(any(Player.class));
    verify(playerEventService, never()).send(any(PlayerEvent.class));
  }
 @Test
 public void tournamentTableShouldNotRetrievePlayersMainAccount() {
   table.setShowInLobby(false);
   table.setGameId(1l);
   host = gameHost(new InMemoryGameRepository(gameRules));
   BigDecimal playerId = BigDecimal.valueOf(54321);
   CommandWrapper aCommand =
       new CommandWrapper(table.getTableId(), 1l, playerId, SESSION_ID, "aCommand");
   aCommand.setRequestId(UUID);
   when(playerRepository.findSummaryByPlayerAndSession(playerId, SESSION_ID))
       .thenReturn(
           aPlayerSessionSummary(playerId, "", BigDecimal.valueOf(10), BigDecimal.valueOf(100)));
   List<HostDocument> documents = host.execute(table, aCommand);
   assertEquals(1, documents.size());
   assertThat((ErrorHostDocument) documents.get(0), Matchers.isA(ErrorHostDocument.class));
 }
  @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()));
  }