@Test
 public void testBottomLetterPressedWithOneItemInAnswer() {
   when(mockStore.state())
       .thenReturn(
           createState("test", singletonList(new Letter(TOP, 'e')), singletonList("test"), 0, 1L));
   actionCreator.bottomLetterPressed();
   verifySingleActionDispatched(Action.BottomPressed.INSTANCE);
 }
 @Test
 public void testBottomLetterPressedWithEmptyAnswer() {
   when(mockStore.state())
       .thenReturn(
           createState("test", Collections.<Letter>emptyList(), singletonList("test"), 0, 1L));
   actionCreator.bottomLetterPressed();
   verifySingleActionDispatched(Action.BottomPressed.INSTANCE);
 }
  @Test
  public void testDismissWordLoadError() {
    actionCreator.dismissWordLoadError();

    ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class);
    verify(mockStore, times(1)).dispatch(actionCaptor.capture());

    List<Action> capturedActions = actionCaptor.getAllValues();

    assertEquals(capturedActions.get(0), Action.DismissLoadWordError.INSTANCE);
  }
 @Test
 public void testRightLetterPressedWithThreeItemsInAnswer() {
   when(mockStore.state())
       .thenReturn(
           createState(
               "test",
               asList(new Letter(TOP, 'e'), new Letter(RIGHT, 's'), new Letter(BOTTOM, 't')),
               singletonList("test"),
               0,
               1L));
   actionCreator.rightLetterPressed();
   verifySingleActionDispatched(Action.RightPressed.INSTANCE);
 }
  @Test
  public void testGameOver() {
    actionCreator.gameOver();

    ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class);
    verify(mockStore, times(1)).dispatch(actionCaptor.capture());

    List<Action> capturedActions = actionCaptor.getAllValues();

    Action.Navigate firstAction = (Action.Navigate) capturedActions.get(0);
    assertEquals(firstAction.getPage().getLayoutId(), R.layout.lose);
    assertEquals(firstAction.getAddToBackStack(), false);
  }
  @Test
  public void testBonusTimeFullForBottomLetterPressedWithCorrectAnswer() {
    when(mockStore.state())
        .thenReturn(createState("test", toListOfLetters("test"), singletonList("test"), 0, 1L));
    actionCreator.bottomLetterPressed();

    ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class);
    verify(mockStore, times(2)).dispatch(actionCaptor.capture());

    List<Action> capturedActions = actionCaptor.getAllValues();

    Action.NextGame nextGameAction = (Action.NextGame) capturedActions.get(1);
    assertEquals(nextGameAction.getBonusTime(), ActionCreator.TIME_BONUS);
  }
  @Test
  public void testBottomLetterPressedWithIncorrectAnswer() {
    when(mockStore.state())
        .thenReturn(createState("test", toListOfLetters("estt"), singletonList("test"), 0, 1L));
    actionCreator.bottomLetterPressed();

    ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class);
    verify(mockStore, times(2)).dispatch(actionCaptor.capture());

    List<Action> capturedActions = actionCaptor.getAllValues();

    assertEquals(capturedActions.get(0), Action.BottomPressed.INSTANCE);
    assertTrue(capturedActions.get(1) instanceof Action.ResetGame);
  }
  @Test
  public void testBottomLetterPressedWithCorrectAnswerAndErrorOccurs() {
    when(mockRepository.getRandomWord()).thenReturn(Observable.<Word>error(new Exception()));
    when(mockStore.state())
        .thenReturn(createState("test", toListOfLetters("test"), singletonList("test"), 0, 1L));

    actionCreator.bottomLetterPressed();

    ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class);
    verify(mockStore, times(3)).dispatch(actionCaptor.capture());

    List<Action> capturedActions = actionCaptor.getAllValues();

    assertEquals(capturedActions.get(0), Action.BottomPressed.INSTANCE);
    assertEquals(capturedActions.get(1), Action.Back.INSTANCE);
    assertEquals(capturedActions.get(2), Action.LoadWordError.INSTANCE);
  }
  @Test
  public void testInitiateGameError() {
    when(mockRepository.getRandomWord()).thenReturn(Observable.<Word>error(new Exception()));

    actionCreator.initiateGame();

    ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class);
    verify(mockStore, times(3)).dispatch(actionCaptor.capture());

    List<Action> capturedActions = actionCaptor.getAllValues();

    Action.Navigate firstAction = (Action.Navigate) capturedActions.get(0);
    assertEquals(firstAction.getPage().getLayoutId(), R.layout.loading);
    assertEquals(firstAction.getAddToBackStack(), true);

    assertEquals(capturedActions.get(1), Action.Back.INSTANCE);
    assertEquals(capturedActions.get(2), Action.LoadWordError.INSTANCE);
  }
  @Test
  public void testInitiateGame() {
    actionCreator.initiateGame();

    ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class);
    verify(mockStore, times(3)).dispatch(actionCaptor.capture());

    List<Action> capturedActions = actionCaptor.getAllValues();

    Action.Navigate firstAction = (Action.Navigate) capturedActions.get(0);
    assertEquals(firstAction.getPage().getLayoutId(), R.layout.loading);
    assertEquals(firstAction.getAddToBackStack(), true);

    Action.InitGame secondAction = (Action.InitGame) capturedActions.get(1);
    assertEquals(secondAction.getWord(), testWord);
    assertEquals(secondAction.getFinishTime(), ActionCreator.GAME_DURATION);

    Action.Navigate thirdAction = (Action.Navigate) capturedActions.get(2);
    assertEquals(thirdAction.getPage().getLayoutId(), R.layout.game);
    assertEquals(thirdAction.getAddToBackStack(), false);
  }
  @Test
  public void testBonusTimeCappedForRightLetterPressedWithCorrectAnswer() {
    when(mockStore.state())
        .thenReturn(
            createState(
                "test",
                toListOfLetters("test"),
                singletonList("test"),
                0,
                ActionCreator.GAME_DURATION));
    when(mockClock.millis()).thenReturn(1L);
    actionCreator.rightLetterPressed();

    ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class);
    verify(mockStore, times(2)).dispatch(actionCaptor.capture());

    List<Action> capturedActions = actionCaptor.getAllValues();

    Action.NextGame nextGameAction = (Action.NextGame) capturedActions.get(1);
    assertEquals(nextGameAction.getBonusTime(), 1L);
  }