@Override public void seekTo(long positionInMillis) throws IllegalStateException { seekToPositionInMillis = positionInMillis; mediaPlayer.seekTo(positionInMillis); }
@Test public void whenSeeking_thenSeeksToPosition() { long seekPositionInMillis = TWO_MINUTES_IN_MILLIS; player.seekTo(seekPositionInMillis); verify(mediaPlayer).seekTo(seekPositionInMillis); }
@Test public void givenPositionThatDiffersFromPlayheadPosition_whenStartingPlayAtVideoPosition_thenSeeksToVideoPosition() { long differentPositionInMillis = givenPositionThatDiffersFromPlayheadPosition(); player.playAt(differentPositionInMillis); ArgumentCaptor<DelayedActionExecutor.Action> argumentCaptor = ArgumentCaptor.forClass(DelayedActionExecutor.Action.class); verify(delayedActionExecutor).performAfterDelay(argumentCaptor.capture(), eq(DELAY_MILLIS)); argumentCaptor.getValue().perform(); verify(mediaPlayer).seekTo(differentPositionInMillis); }
@Test public void givenMediaPlayerIsInPlaybackState_whenSeeking_thenSeeksToPosition() { givenMediaPlayerIsPrepared(); given(playbackStateChecker.isInPlaybackState(eq(mediaPlayer), any(PlaybackStateChecker.PlaybackState.class))) .willReturn(IS_IN_PLAYBACK_STATE); facade.seekTo(TEN_SECONDS_IN_MILLIS); verify(mediaPlayer).seekTo(TEN_SECONDS_IN_MILLIS); }
@Test public void givenMediaPlayerIsNotInPlaybackState_whenSeeking_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.seekTo(TEN_SECONDS_IN_MILLIS); }