@Override public long playheadPositionInMillis() throws IllegalStateException { return isSeeking() ? seekToPositionInMillis : mediaPlayer.currentPositionInMillis(); }
private long givenPositionThatDiffersFromPlayheadPosition() { given(mediaPlayer.currentPositionInMillis()).willReturn(0); return 1; }
@Test public void givenMediaPlayerIsNotInPlaybackState_whenGettingPosition_thenThrowsIllegalStateException() { thrown.expect(ExceptionMatcher.matches(ERROR_MESSAGE, IllegalStateException.class)); given(playbackStateChecker.isInPlaybackState(eq(mediaPlayer), any(PlaybackStateChecker.PlaybackState.class))) .willReturn(IS_NOT_IN_PLAYBACK_STATE); facade.currentPositionInMillis(); }
@Test public void whenStartingPlayAtVideoPosition_thenMediaPlayerStarts() { given(mediaPlayer.currentPositionInMillis()).willReturn((int) BEGINNING_POSITION); player.playAt(BEGINNING_POSITION); verify(mediaPlayer).start(surface); }
@Test public void whenStartingPlayAtVideoPosition_thenNotifiesStateListenersThatVideoIsPlaying() { given(mediaPlayer.currentPositionInMillis()).willReturn((int) BEGINNING_POSITION); player.playAt(BEGINNING_POSITION); verify(stateChangedListener).onVideoPlaying(); }
@Test public void whenStartingPlayAtVideoPosition_thenStartsBeatingHeart() { given(mediaPlayer.currentPositionInMillis()).willReturn((int) BEGINNING_POSITION); player.playAt(BEGINNING_POSITION); verify(heart).startBeatingHeart(); }
@Test public void givenMediaPlayerIsInPlaybackState_whenGettingPosition_thenReturnsPosition() { givenMediaPlayerIsPrepared(); given(playbackStateChecker.isInPlaybackState(eq(mediaPlayer), any(PlaybackStateChecker.PlaybackState.class))) .willReturn(IS_IN_PLAYBACK_STATE); given(mediaPlayer.getCurrentPosition()).willReturn(ANY_POSITION); int currentPosition = facade.currentPositionInMillis(); assertThat(currentPosition).isEqualTo(ANY_POSITION); }
@Test public void givenPlayerIsNotSeeking_whenGettingPlayheadPosition_thenReturnsCurrentMediaPlayerPosition() { given(mediaPlayer.currentPositionInMillis()).willReturn(ONE_SECOND_IN_MILLIS); long playheadPositionInMillis = player.playheadPositionInMillis(); assertThat(playheadPositionInMillis).isEqualTo(ONE_SECOND_IN_MILLIS); }