@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());
 }
 private GameInitialiser.GameInitialisationContext defaultEventContext() {
   GameInitialiser.GameInitialisationContext initialisationContext =
       new GameInitialiser.GameInitialisationContext(
           new com.yazino.game.api.ScheduledEvent(
               0, 100, "", "", Collections.<String, String>emptyMap(), true),
           wallet,
           externalGameService,
           gameRules);
   initialisationContext.setAllowedToMoveToNextGame(false);
   return initialisationContext;
 }
  @Test
  public void shouldntRunPreprocessorsIfFlagSet() {
    Table table = tableWithPhase(Playing, 100L);
    when(wallet.getTable()).thenReturn(table);

    GameInitialiser.GameInitialisationContext context = defaultEventContext();
    context.setRunPreProcessors(false);
    EventPreprocessor processor = mockEventPreprocessor(true);
    underTest.setEventPreInitialisationProcessors(toList(processor));
    underTest.initialiseGame(context);
    verifyZeroInteractions(processor);
  }
 @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);
 }
  @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);
  }
 @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()));
 }
  @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()));
  }