コード例 #1
0
  @Test
  public void testPlayersGetNewStatus() throws com.yazino.game.api.GameException {
    whenGameStart();
    command = commandFrom(PLAYER1_ID);
    com.yazino.game.api.GamePlayer p1 =
        new com.yazino.game.api.GamePlayer(PLAYER1_ID, SESSION_ID, "");
    com.yazino.game.api.GamePlayer p2 =
        new com.yazino.game.api.GamePlayer(PLAYER2_ID, SESSION_ID, "");
    table.setCurrentGame(gameStatus1);
    whenPlayers(p1, p2);
    when(gameRules.getObservableStatus(gameStatus1, getContextFor(p1, false, table.getIncrement())))
        .thenReturn(new PrintlnStatus());
    when(gameRules.getObservableStatus(gameStatus1, getContextFor(p2, true, table.getIncrement())))
        .thenReturn(new PrintlnStatus());
    final com.yazino.game.api.ExecutionResult result =
        new com.yazino.game.api.ExecutionResult.Builder(gameRules, gameStatus1)
            .scheduledEvents(emptyEvents)
            .build();
    when(gameRules.execute(
            isA(com.yazino.game.api.ExecutionContext.class), eq(command.toCommand(PLAYER_NAME))))
        .thenReturn(result);
    final List<HostDocument> hostDocuments = executeCommand();

    // table.lastGameChanges?
    assertThat(hostDocuments.size(), is(equalTo(2)));
    assertThat(
        (GameStatusHostDocument) hostDocuments.get(0), Matchers.isA(GameStatusHostDocument.class));
    assertThat(
        (GameStatusHostDocument) hostDocuments.get(1), Matchers.isA(GameStatusHostDocument.class));
  }
コード例 #2
0
 @Test
 public void testObserversGetNotified() throws com.yazino.game.api.GameException {
   whenGameStart();
   final com.yazino.game.api.ExecutionResult executionResult =
       new com.yazino.game.api.ExecutionResult.Builder(
               new PrintlnRules(), new GameStatus(new PrintlnStatus()))
           .scheduledEvents(emptyEvents)
           .build();
   when(gameRules.getObservableStatus(gameStatus1, getContextFor(null)))
       .thenReturn(new PrintlnStatus());
   when(gameRules.execute(
           isA(com.yazino.game.api.ExecutionContext.class), eq(command.toCommand(PLAYER_NAME))))
       .thenReturn(executionResult);
   final List<HostDocument> hostDocuments = executeCommand();
   assertThat(
       (GameStatusHostDocument) hostDocuments.get(0), Matchers.isA(GameStatusHostDocument.class));
   assertThat(
       (GameStatusHostDocument) hostDocuments.get(1), Matchers.isA(GameStatusHostDocument.class));
 }
コード例 #3
0
 @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));
 }
コード例 #4
0
 @SuppressWarnings({"ThrowableInstanceNeverThrown"})
 @Test
 public void senderGetsErrorMessageWhenExceptionThrownInGameHost()
     throws com.yazino.game.api.GameException {
   whenGameStart();
   com.yazino.game.api.ParameterisedMessage pm =
       new com.yazino.game.api.ParameterisedMessage("UPS!");
   when(gameRules.execute(
           isA(com.yazino.game.api.ExecutionContext.class), eq(command.toCommand(PLAYER_NAME))))
       .thenThrow(new com.yazino.game.api.GameException(pm));
   final List<HostDocument> hostDocuments = executeCommand();
   assertThat((ErrorHostDocument) hostDocuments.get(1), Matchers.isA(ErrorHostDocument.class));
 }
コード例 #5
0
 @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));
 }