AudioPlayerActivity extends RoboActionBarActivity { @Subscribe public void onEvent(AudioPlayingEvent event) { Log.d(Support.MYPODCASTS_TAG, "[AudioPlayerActivity][onEvent][AudioPlayingEvent]"); audioPlayer = event.getAudioPlayer(); audioPlayer.seekTo( episodeCheckpoint.getLastCheckpointPosition(episode, playerCurrentPosition) ); mediaController.setMediaPlayer(audioPlayer); mediaController.setAnchorView(findViewById(R.id.audio_view)); mediaController.show(); if (episode != null) { episodeDescription.setText(fromHtml(episode.getDescription())); } }  @Override boolean onOptionsItemSelected(MenuItem item); @Override boolean onTouchEvent(MotionEvent event); @Subscribe void onEvent(AudioPlayingEvent event); @Subscribe void onEvent(AudioStoppedEvent event);  }
@Test public void itShowsMediaControlWhenAudioStartToPlay() { AudioPlayerActivity activity = createActivity(); activity.onEvent(new AudioPlayingEvent(audioPlayerMock)); verify(mediaControllerMock).show(); }
@Test public void itBindsAudioPlayerWithMediaControl() { AudioPlayerActivity activity = createActivity(); activity.onEvent(new AudioPlayingEvent(audioPlayerMock)); verify(mediaControllerMock).setMediaPlayer(audioPlayerMock); }
@Test public void itAnchorsMediaControllerToAudioView() { AudioPlayerActivity activity = createActivity(); View audioView = activity.findViewById(R.id.audio_view); activity.onEvent(new AudioPlayingEvent(audioPlayerMock)); verify(mediaControllerMock).setAnchorView(audioView); }
@Test public void itSeeksToInitialPositionOnCreate() { int initialPosition = 0; AudioPlayerActivity activity = createActivity(); activity.onEvent(new AudioPlayingEvent(audioPlayerMock)); verify(audioPlayerMock).seekTo(initialPosition); }
@Test public void itSetsEpisodeDescription() { episode = new Episode() { @Override public String getDescription() { return "<span>Awesome Episode</span>"; } }; AudioPlayerActivity activity = createActivity(); activity.onEvent(new AudioPlayingEvent(audioPlayerMock)); TextView textView = (TextView) activity.findViewById(R.id.episode_description); String description = valueOf(textView.getText()); assertThat(description, is("Awesome Episode")); }
@Test public void itSetsToEmptyDescriptionWhenEpisodeIsNull() { episode = null; AudioPlayerActivity activity = createActivity(); activity.onEvent(new AudioPlayingEvent(audioPlayerMock)); TextView textView = (TextView) activity.findViewById(R.id.episode_description); String description = valueOf(textView.getText()); assertThat(description, is("")); }
@Test public void itFinishesActivityOnAudioPlayerStoppedEvent() { AudioPlayerActivity activity = createActivity(); activity.onEvent(new AudioStoppedEvent()); assertThat(activity.isFinishing(), is(true)); }