コード例 #1
0
 @Test
 public void shouldCreateNewGameWhenNotAllowed() {
   Table table = tableWithPhase(GameFinished, 6L);
   when(wallet.getTable()).thenReturn(table);
   GameInitialiser.GameInitialisationContext context = defaultEventContext();
   context.setAllowedToMoveToNextGame(false);
   underTest.initialiseGame(context);
   assertEquals(Long.valueOf(6), table.getGameId());
 }
コード例 #2
0
 @Test
 public void shouldntRunPostProcessorsWhenDisabledAndNewGameCreated() {
   Table table = tableWithPhase(null, 100L);
   when(wallet.getTable()).thenReturn(table);
   GameInitialiser.GameInitialisationContext context = defaultEventContext();
   context.setRunPostProcessors(false);
   Postprocessor processor = mockPostProcessor();
   underTest.setPostInitialisationProcessors(toList(processor));
   underTest.initialiseGame(context);
   assertEquals(Long.valueOf(1), table.getGameId());
   verifyZeroInteractions(processor);
 }
コード例 #3
0
  @Test
  public void shouldReturnFalseIfAPreProcessorFails() {
    Table table = tableWithPhase(Playing, 100L);
    when(wallet.getTable()).thenReturn(table);

    EventPreprocessor processor3 = mockEventPreprocessor(true);
    underTest.setEventPreInitialisationProcessors(
        Arrays.asList(mockEventPreprocessor(true), mockEventPreprocessor(false), processor3));
    boolean successful = underTest.runPreProcessors(gameRules, defaultEventContext());
    assertFalse(successful);
    assertEquals(Long.valueOf(100), table.getGameId());
    verifyZeroInteractions(processor3);
  }
コード例 #4
0
  @Test
  public void shouldntRunPostProcessorsWhenDisabledAndNextGameCreated() {
    Table table = tableWithPhase(GameFinished, 6L);
    when(wallet.getTable()).thenReturn(table);
    GameInitialiser.GameInitialisationContext context = defaultEventContext();
    context.setAllowedToMoveToNextGame(true);
    context.setRunPostProcessors(false);
    when(gameRules.isComplete(table.getCurrentGame())).thenReturn(true);
    underTest.setPostInitialisationProcessors(toList(postprocessor));

    underTest.initialiseGame(context);

    assertEquals(Long.valueOf(7), table.getGameId());
    verifyZeroInteractions(postprocessor);
  }
コード例 #5
0
 @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);
 }
コード例 #6
0
 @SuppressWarnings({"unchecked"})
 @Test
 public void shouldUpdateGameIdWhenNewGameCreatedAndNotifyPostProcessors() {
   Table table = tableWithPhase(null, 100L);
   when(wallet.getTable()).thenReturn(table);
   GameInitialiser.GameInitialisationContext context = defaultEventContext();
   Postprocessor processor = mockPostProcessor();
   underTest.setPostInitialisationProcessors(toList(processor));
   underTest.initialiseGame(context);
   assertEquals(Long.valueOf(1), table.getGameId());
   verify(processor)
       .postProcess(
           any(com.yazino.game.api.ExecutionResult.class),
           any(com.yazino.game.api.Command.class),
           eq(table),
           anyString(),
           anyList(),
           eq(context.getPlayerId()));
 }
コード例 #7
0
 @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());
 }
コード例 #8
0
  @Test
  public void shouldIncrementGameIdWhenCreatedNextGameAndNotifyPostProcessors() {
    Table table = tableWithPhase(GameFinished, 6L);
    when(wallet.getTable()).thenReturn(table);
    GameInitialiser.GameInitialisationContext context = defaultEventContext();
    context.setAllowedToMoveToNextGame(true);
    when(gameRules.isComplete(table.getCurrentGame())).thenReturn(true);
    underTest.setPostInitialisationProcessors(toList(postprocessor));

    underTest.initialiseGame(context);

    assertEquals(Long.valueOf(7), table.getGameId());
    verify(postprocessor)
        .postProcess(
            any(com.yazino.game.api.ExecutionResult.class),
            any(com.yazino.game.api.Command.class),
            eq(table),
            anyString(),
            anyList(),
            eq(context.getPlayerId()));
  }