コード例 #1
0
  @Before
  public void setup() {
    mockClock = mock(Clock.class);
    when(mockClock.millis()).thenReturn(0L);

    mockRepository = mock(WordRepository.class);
    when(mockRepository.getRandomWord()).thenReturn(Observable.just(testWord));

    //noinspection unchecked
    mockStore = mock(Store.class);

    actionCreator = new ActionCreator(mockStore, mockRepository, mockClock);
  }
コード例 #2
0
  @Test
  public void testBonusTimeCappedForBottomLetterPressedWithCorrectAnswer() {
    when(mockStore.state())
        .thenReturn(
            createState(
                "test",
                toListOfLetters("test"),
                singletonList("test"),
                0,
                ActionCreator.GAME_DURATION));
    when(mockClock.millis()).thenReturn(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(), 1L);
  }