/** Test method for {@link AbstractMediaRouteController#isRemotePlaybackAvailable()}. */ @Test @Feature({"MediaRemote"}) public void testIsRemotePlaybackAvailable() { MediaRouter mediaRouter = mock(MediaRouter.class); AbstractMediaRouteController mediaRouteCtrl = new DummyMediaRouteController(); when(mediaRouter.getSelectedRoute()) .thenReturn(createRouteInfo(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)); when(mediaRouter.isRouteAvailable(any(MediaRouteSelector.class), anyInt())).thenReturn(true); // Default assertFalse(mediaRouteCtrl.isRemotePlaybackAvailable()); ShadowMediaRouter.sMediaRouter = mediaRouter; mediaRouteCtrl = spy(new DummyMediaRouteController()); assertTrue(mediaRouteCtrl.isRemotePlaybackAvailable()); when(mediaRouter.getSelectedRoute()) .thenReturn(createRouteInfo(MediaRouter.RouteInfo.PLAYBACK_TYPE_LOCAL)); assertTrue(mediaRouteCtrl.isRemotePlaybackAvailable()); when(mediaRouter.isRouteAvailable(any(MediaRouteSelector.class), anyInt())).thenReturn(false); assertFalse(mediaRouteCtrl.isRemotePlaybackAvailable()); when(mediaRouter.getSelectedRoute()) .thenReturn(createRouteInfo(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)); assertTrue(mediaRouteCtrl.isRemotePlaybackAvailable()); }
/** * Test method for {@link AbstractMediaRouteController#addMediaStateListener(MediaStateListener)} * and {@link AbstractMediaRouteController#removeMediaStateListener(MediaStateListener)} * * <p>Makes sure that listeners gets notified when they are added and don't get notified when * removed. */ @Test @Feature({"MediaRemote"}) public void testAddRemoveMediaStateListener() { MediaStateListener listener = mock(MediaStateListener.class); MediaStateListener otherListener = mock(MediaStateListener.class); MediaRouter mediaRouter = ShadowMediaRouter.createCapturingMock(); when(mediaRouter.isRouteAvailable(any(MediaRouteSelector.class), anyInt())).thenReturn(true); ShadowMediaRouter.sMediaRouter = mediaRouter; // Creating the MediaRouteController AbstractMediaRouteController mediaRouteController = new DummyMediaRouteController(); assertNotNull(mediaRouteController.getMediaRouter()); // 1. #addMediaStateListener() mediaRouteController.addMediaStateListener(listener); // The route selector should get notified of new states. verify(mediaRouter).addCallback(any(MediaRouteSelector.class), any(Callback.class), anyInt()); verify(listener).onRouteAvailabilityChanged(true); // Check the behavior difference between the first and subsequent additions. mediaRouteController.addMediaStateListener(otherListener); verify(otherListener).onRouteAvailabilityChanged(true); // The call count should not change. verify(mediaRouter).addCallback(any(MediaRouteSelector.class), any(Callback.class), anyInt()); verify(listener).onRouteAvailabilityChanged(true); // 2. #removeMediaStateListener() mediaRouteController.removeMediaStateListener(otherListener); // The removed listener should not be notified of changes anymore. when(mediaRouter.isRouteAvailable(any(MediaRouteSelector.class), anyInt())).thenReturn(false); ShadowMediaRouter.sCallback.onRouteRemoved(mediaRouter, null); verifyNoMoreInteractions(otherListener); verify(listener).onRouteAvailabilityChanged(false); verify(mediaRouter, times(0)).removeCallback(any(Callback.class)); mediaRouteController.removeMediaStateListener(listener); when(mediaRouter.isRouteAvailable(any(MediaRouteSelector.class), anyInt())).thenReturn(true); ShadowMediaRouter.sCallback.onRouteAdded(mediaRouter, null); verifyNoMoreInteractions(otherListener); verifyNoMoreInteractions(listener); verify(mediaRouter).removeCallback(any(Callback.class)); }