PlaybackVolumeUpdater { public void updateVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, long feedId, VolumeAdaptionSetting volumeAdaptionSetting) { Playable playable = mediaPlayer.getPlayable(); if (playable instanceof FeedMedia) { updateFeedMediaVolumeIfNecessary(mediaPlayer, feedId, volumeAdaptionSetting, (FeedMedia) playable); } }  void updateVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, long feedId,
                                        VolumeAdaptionSetting volumeAdaptionSetting);  }
@Test public void noChangeIfNoFeedMediaPlaying() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PAUSED); Playable noFeedMedia = mock(Playable.class); when(mediaPlayer.getPlayable()).thenReturn(noFeedMedia); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void noChangeIfPlayerStatusIsError() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.ERROR); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void noChangeIfPlayerStatusIsIndeterminate() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.INDETERMINATE); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void noChangeIfPlayerStatusIsStopped() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.STOPPED); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void noChangeIfPlayableIsNoItemOfAffectedFeed() { when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PLAYING); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(feedMedia.getItem().getFeed().getId()).thenReturn(FEED_ID + 1); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPaused() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PAUSED); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); FeedPreferences feedPreferences = feedMedia.getItem().getFeed().getPreferences(); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION); verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPrepared() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PREPARED); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); FeedPreferences feedPreferences = feedMedia.getItem().getFeed().getPreferences(); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION); verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsInitializing() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.INITIALIZING); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); FeedPreferences feedPreferences = feedMedia.getItem().getFeed().getPreferences(); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION); verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPreparing() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PREPARING); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); FeedPreferences feedPreferences = feedMedia.getItem().getFeed().getPreferences(); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION); verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsSeeking() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.SEEKING); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); FeedPreferences feedPreferences = feedMedia.getItem().getFeed().getPreferences(); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION); verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).resume(); }
@Test public void updatesPreferencesAndForcesVolumeChangeForLoadedFeedMediaIfPlayerStatusIsPlaying() { PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater(); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PLAYING); FeedMedia feedMedia = mockFeedMedia(); when(mediaPlayer.getPlayable()).thenReturn(feedMedia); FeedPreferences feedPreferences = feedMedia.getItem().getFeed().getPreferences(); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.HEAVY_REDUCTION); verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.HEAVY_REDUCTION); verify(mediaPlayer, times(1)).pause(false, false); verify(mediaPlayer, times(1)).resume(); }