Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61c1c9f0 authored by hughchen's avatar hughchen
Browse files

Add test case for media manager

Bug: 121083246
Test: make -j50 RunSettingsLibRoboTests
Change-Id: I60b11ddef57a303c154e5e04e6425cf632842d7a
parent f4caa428
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.media;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.when;

import android.bluetooth.BluetoothProfile;
import android.content.Context;

import com.android.settingslib.bluetooth.CachedBluetoothDevice;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

@RunWith(RobolectricTestRunner.class)
public class BluetoothMediaDeviceTest {

    @Mock
    private CachedBluetoothDevice mDevice;

    private Context mContext;
    private BluetoothMediaDevice mBluetoothMediaDevice;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = RuntimeEnvironment.application;

        when(mDevice.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(true);
        when(mDevice.isActiveDevice(BluetoothProfile.HEARING_AID)).thenReturn(true);

        mBluetoothMediaDevice = new BluetoothMediaDevice(mContext, mDevice);
    }

    @Test
    public void connect_setActiveSuccess_isConnectedReturnTrue() {
        when(mDevice.setActive()).thenReturn(true);

        assertThat(mBluetoothMediaDevice.connect()).isTrue();
    }

    @Test
    public void connect_setActiveFail_isConnectedReturnFalse() {
        when(mDevice.setActive()).thenReturn(false);

        assertThat(mBluetoothMediaDevice.connect()).isFalse();
    }
}
+416 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.media;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;

import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@RunWith(RobolectricTestRunner.class)
public class BluetoothMediaManagerTest {

    private static final String TEST_ADDRESS = "11:22:33:44:55:66";

    @Mock
    private LocalBluetoothManager mLocalBluetoothManager;
    @Mock
    private LocalBluetoothProfileManager mProfileManager;
    @Mock
    private A2dpProfile mA2dpProfile;
    @Mock
    private HearingAidProfile mHapProfile;
    @Mock
    private CachedBluetoothDeviceManager mCachedDeviceManager;
    @Mock
    private BluetoothEventManager mEventManager;
    @Mock
    private MediaManager.MediaDeviceCallback mCallback;

    private BluetoothMediaManager mMediaManager;
    private Context mContext;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = RuntimeEnvironment.application;

        when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager);
        when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
        when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
        when(mProfileManager.getHearingAidProfile()).thenReturn(mHapProfile);
        when(mLocalBluetoothManager.getEventManager()).thenReturn(mEventManager);

        mMediaManager = new BluetoothMediaManager(mContext, mLocalBluetoothManager, null);
    }

    @Test
    public void startScan_haveA2dpProfileConnectedBluetoothDevice_shouldAddDevice() {
        final List<BluetoothDevice> devices = new ArrayList<>();
        final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
        devices.add(bluetoothDevice);

        when(mA2dpProfile.getConnectedDevices()).thenReturn(devices);
        when(mCachedDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
        when(cachedDevice.isConnected()).thenReturn(true);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        mMediaManager.startScan();
        assertThat(mMediaManager.mMediaDevices).hasSize(devices.size());
    }

    @Test
    public void startScan_haveA2dpProfileDisconnectedBluetoothDevice_shouldNotAddDevice() {
        final List<BluetoothDevice> devices = new ArrayList<>();
        final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
        devices.add(bluetoothDevice);

        when(mA2dpProfile.getConnectedDevices()).thenReturn(devices);
        when(mCachedDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
        when(cachedDevice.isConnected()).thenReturn(false);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        mMediaManager.startScan();
        assertThat(mMediaManager.mMediaDevices).isEmpty();
    }

    @Test
    public void startScan_noA2dpProfileBluetoothDevice_shouldNotAddDevice() {
        final List<BluetoothDevice> devices = new ArrayList<>();

        when(mA2dpProfile.getConnectedDevices()).thenReturn(devices);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        mMediaManager.startScan();
        assertThat(mMediaManager.mMediaDevices).isEmpty();
    }

    @Test
    public void startScan_haveHapProfileConnectedBluetoothDevice_shouldAddDevice() {
        final List<BluetoothDevice> devices = new ArrayList<>();
        final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
        devices.add(bluetoothDevice);

        when(mHapProfile.getConnectedDevices()).thenReturn(devices);
        when(mCachedDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
        when(cachedDevice.isConnected()).thenReturn(true);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        mMediaManager.startScan();
        assertThat(mMediaManager.mMediaDevices).hasSize(devices.size());
    }

    @Test
    public void startScan_noHapProfileBluetoothDevice_shouldNotAddDevice() {
        final List<BluetoothDevice> devices = new ArrayList<>();

        when(mHapProfile.getConnectedDevices()).thenReturn(devices);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        mMediaManager.startScan();
        assertThat(mMediaManager.mMediaDevices).isEmpty();
    }

    @Test
    public void starScan_a2dpAndHapProfileNotReady_shouldRegisterCallback() {
        final Collection<CachedBluetoothDevice> mDevices = new ArrayList<>();
        final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        mDevices.add(cachedDevice);

        when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mDevices);
        when(mA2dpProfile.isProfileReady()).thenReturn(false);
        when(mHapProfile.isProfileReady()).thenReturn(false);

        mMediaManager.startScan();

        verify(mProfileManager).addServiceListener(mMediaManager);
    }

    @Test
    public void starScan_a2dpAndHapProfileReady_shouldNotRegisterCallback() {
        final Collection<CachedBluetoothDevice> mDevices = new ArrayList<>();
        final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        mDevices.add(cachedDevice);

        when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mDevices);
        when(mA2dpProfile.isProfileReady()).thenReturn(true);
        when(mHapProfile.isProfileReady()).thenReturn(true);

        mMediaManager.startScan();

        verify(mProfileManager, never()).addServiceListener(mMediaManager);
    }

    @Test
    public void onServiceConnected_a2dpAndHapProfileNotReady_doNothing() {
        final Collection<CachedBluetoothDevice> mDevices = new ArrayList<>();
        final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        mDevices.add(cachedDevice);

        when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mDevices);
        when(mA2dpProfile.isProfileReady()).thenReturn(false);
        when(mHapProfile.isProfileReady()).thenReturn(false);

        mMediaManager.startScan();
        mMediaManager.onServiceConnected();

        verify(mProfileManager, never()).removeServiceListener(mMediaManager);
    }

    @Test
    public void onDeviceAttributesChanged_a2dpAndHapProfileReady_shouldUnregisterCallback() {
        final Collection<CachedBluetoothDevice> mDevices = new ArrayList<>();
        final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        mDevices.add(cachedDevice);

        when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mDevices);
        when(mA2dpProfile.isProfileReady()).thenReturn(true);
        when(mHapProfile.isProfileReady()).thenReturn(true);

        mMediaManager.startScan();
        mMediaManager.onServiceConnected();

        verify(mProfileManager).removeServiceListener(mMediaManager);
    }

    @Test
    public void onBluetoothStateChanged_bluetoothStateIsOn_callOnDeviceListAdded() {
        mMediaManager.registerCallback(mCallback);
        mMediaManager.onBluetoothStateChanged(BluetoothAdapter.STATE_ON);

        verify(mCallback).onDeviceListAdded(any());
    }

    @Test
    public void onBluetoothStateChanged_bluetoothStateIsOff_callOnDeviceListRemoved() {
        final BluetoothMediaDevice device1 = mock(BluetoothMediaDevice.class);
        final BluetoothMediaDevice device2 = mock(BluetoothMediaDevice.class);
        mMediaManager.mMediaDevices.add(device1);
        mMediaManager.mMediaDevices.add(device2);

        mMediaManager.registerCallback(mCallback);
        mMediaManager.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        verify(mCallback).onDeviceListRemoved(any());
    }

    @Test
    public void onDeviceAdded_cachedDeviceIsConnected_callOnDeviceAdded() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);

        when(device.isConnectedHearingAidDevice()).thenReturn(true);
        when(device.isConnectedA2dpDevice()).thenReturn(true);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        mMediaManager.registerCallback(mCallback);
        mMediaManager.onDeviceAdded(device);

        assertThat(mMediaManager.mMediaDevices).hasSize(1);
        verify(mCallback).onDeviceAdded(any());

    }

    @Test
    public void onDeviceAdded_cachedDeviceIsDisconnected_doNothing() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);

        when(device.isConnectedHearingAidDevice()).thenReturn(false);
        when(device.isConnectedA2dpDevice()).thenReturn(false);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        mMediaManager.registerCallback(mCallback);
        mMediaManager.onDeviceAdded(device);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        verify(mCallback, never()).onDeviceAdded(any());

    }

    @Test
    public void onDeviceDeleted_cachedDeviceIsConnected_doNothing() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
        final BluetoothMediaDevice bluetoothMediaDevice = mock(BluetoothMediaDevice.class);
        mMediaManager.mMediaDevices.add(bluetoothMediaDevice);

        when(device.isConnectedHearingAidDevice()).thenReturn(true);
        when(device.isConnectedA2dpDevice()).thenReturn(true);
        when(device.getAddress()).thenReturn(TEST_ADDRESS);
        when(bluetoothMediaDevice.getId()).thenReturn(TEST_ADDRESS);

        assertThat(mMediaManager.mMediaDevices).hasSize(1);
        mMediaManager.registerCallback(mCallback);
        mMediaManager.onDeviceDeleted(device);

        assertThat(mMediaManager.mMediaDevices).hasSize(1);
        verify(mCallback, never()).onDeviceRemoved(any());
    }

    @Test
    public void onDeviceDeleted_cachedDeviceIsDisconnected_callOnDeviceRemoved() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
        final BluetoothMediaDevice bluetoothMediaDevice = mock(BluetoothMediaDevice.class);
        mMediaManager.mMediaDevices.add(bluetoothMediaDevice);

        when(device.isConnectedHearingAidDevice()).thenReturn(false);
        when(device.isConnectedA2dpDevice()).thenReturn(false);
        when(device.getAddress()).thenReturn(TEST_ADDRESS);
        when(bluetoothMediaDevice.getId()).thenReturn(TEST_ADDRESS);

        assertThat(mMediaManager.mMediaDevices).hasSize(1);
        mMediaManager.registerCallback(mCallback);
        mMediaManager.onDeviceDeleted(device);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        verify(mCallback).onDeviceRemoved(any());
    }

    @Test
    public void onProfileConnectionStateChanged_cachedDeviceIsConnect_callOnDeviceAdded() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);

        when(device.isConnectedHearingAidDevice()).thenReturn(true);
        when(device.isConnectedA2dpDevice()).thenReturn(true);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        mMediaManager.registerCallback(mCallback);
        mMediaManager.onProfileConnectionStateChanged(device, 0, 0);

        assertThat(mMediaManager.mMediaDevices).hasSize(1);
        verify(mCallback).onDeviceAdded(any());
    }

    @Test
    public void onProfileConnectionStateChanged_cachedDeviceIsDisconnect_callOnDeviceRemoved() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
        final BluetoothMediaDevice bluetoothMediaDevice = mock(BluetoothMediaDevice.class);
        mMediaManager.mMediaDevices.add(bluetoothMediaDevice);

        when(device.isConnectedHearingAidDevice()).thenReturn(false);
        when(device.isConnectedA2dpDevice()).thenReturn(false);
        when(device.getAddress()).thenReturn(TEST_ADDRESS);
        when(bluetoothMediaDevice.getId()).thenReturn(TEST_ADDRESS);

        assertThat(mMediaManager.mMediaDevices).hasSize(1);
        mMediaManager.registerCallback(mCallback);
        mMediaManager.onProfileConnectionStateChanged(device, 0, 0);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        verify(mCallback).onDeviceRemoved(any());
    }

    @Test
    public void onAclConnectionStateChanged_cachedDeviceIsConnect_callOnDeviceAdded() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);

        when(device.isConnectedHearingAidDevice()).thenReturn(true);
        when(device.isConnectedA2dpDevice()).thenReturn(true);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        mMediaManager.registerCallback(mCallback);
        mMediaManager.onAclConnectionStateChanged(device, 0);

        assertThat(mMediaManager.mMediaDevices).hasSize(1);
        verify(mCallback).onDeviceAdded(any());
    }

    @Test
    public void onAclConnectionStateChanged_cachedDeviceIsDisconnect_callOnDeviceRemoved() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
        final BluetoothMediaDevice bluetoothMediaDevice = mock(BluetoothMediaDevice.class);
        mMediaManager.mMediaDevices.add(bluetoothMediaDevice);

        when(device.isConnectedHearingAidDevice()).thenReturn(false);
        when(device.isConnectedA2dpDevice()).thenReturn(false);
        when(device.getAddress()).thenReturn(TEST_ADDRESS);
        when(bluetoothMediaDevice.getId()).thenReturn(TEST_ADDRESS);

        assertThat(mMediaManager.mMediaDevices).hasSize(1);
        mMediaManager.registerCallback(mCallback);
        mMediaManager.onAclConnectionStateChanged(device, 0);

        assertThat(mMediaManager.mMediaDevices).isEmpty();
        verify(mCallback).onDeviceRemoved(any());
    }

    @Test
    public void onActiveDeviceChanged_isHapProfile_callOnActiveDeviceChanged() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);

        when(device.getAddress()).thenReturn(TEST_ADDRESS);

        mMediaManager.registerCallback(mCallback);
        mMediaManager.onActiveDeviceChanged(device, BluetoothProfile.HEARING_AID);

        verify(mCallback).onConnectedDeviceChanged(any());
    }

    @Test
    public void onActiveDeviceChanged_isA2dpProfile_callOnActiveDeviceChanged() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);

        when(device.getAddress()).thenReturn(TEST_ADDRESS);

        mMediaManager.registerCallback(mCallback);
        mMediaManager.onActiveDeviceChanged(device, BluetoothProfile.A2DP);

        verify(mCallback).onConnectedDeviceChanged(any());
    }

    @Test
    public void onActiveDeviceChanged_isNotA2dpAndHapProfile_doNothing() {
        final CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);

        when(device.getAddress()).thenReturn(TEST_ADDRESS);

        mMediaManager.registerCallback(mCallback);
        mMediaManager.onActiveDeviceChanged(device, BluetoothProfile.HEALTH);

        verify(mCallback, never()).onConnectedDeviceChanged(any());
    }
}
+136 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.media;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;

import androidx.mediarouter.media.MediaRouteSelector;
import androidx.mediarouter.media.MediaRouter;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

@RunWith(RobolectricTestRunner.class)
public class InfoMediaManagerTest {

    private static final String TEST_PACKAGE_NAME = "com.test.packagename";
    private static final String TEST_ID = "test_id";

    @Mock
    private MediaRouter mMediaRouter;
    @Mock
    private MediaRouteSelector mSelector;

    private InfoMediaManager mInfoMediaManager;
    private Context mContext;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = RuntimeEnvironment.application;

        mInfoMediaManager = new InfoMediaManager(mContext, TEST_PACKAGE_NAME, null);
        mInfoMediaManager.mMediaRouter = mMediaRouter;
        mInfoMediaManager.mSelector = mSelector;
    }

    @Test
    public void stopScan_shouldRemoveCallback() {
        mInfoMediaManager.stopScan();

        verify(mMediaRouter).removeCallback(mInfoMediaManager.mMediaRouterCallback);
    }

    @Test
    public void startScan_shouldAddCallback() {
        mInfoMediaManager.startScan();

        verify(mMediaRouter).addCallback(mSelector, mInfoMediaManager.mMediaRouterCallback,
                MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
    }

    @Test
    public void onRouteAdded_mediaDeviceNotExistInList_addMediaDevice() {
        final MediaRouter.RouteInfo info = mock(MediaRouter.RouteInfo.class);
        when(info.getId()).thenReturn(TEST_ID);

        final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID);
        assertThat(mediaDevice).isNull();

        mInfoMediaManager.mMediaRouterCallback.onRouteAdded(mMediaRouter, info);

        final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0);
        assertThat(infoDevice.getId()).isEqualTo(TEST_ID);
    }

    @Test
    public void onRouteAdded_mediaDeviceExistInList_doNothing() {
        final MediaRouter.RouteInfo info = mock(MediaRouter.RouteInfo.class);
        when(info.getId()).thenReturn(TEST_ID);
        final InfoMediaDevice infoDevice = new InfoMediaDevice(mContext, info);
        mInfoMediaManager.mMediaDevices.add(infoDevice);

        final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID);
        final int size = mInfoMediaManager.mMediaDevices.size();
        assertThat(mediaDevice).isNotNull();

        mInfoMediaManager.mMediaRouterCallback.onRouteAdded(mMediaRouter, info);

        assertThat(mInfoMediaManager.mMediaDevices).hasSize(size);
    }

    @Test
    public void onRouteRemoved_mediaDeviceExistInList_removeMediaDevice() {
        final MediaRouter.RouteInfo info = mock(MediaRouter.RouteInfo.class);
        when(info.getId()).thenReturn(TEST_ID);
        final InfoMediaDevice infoDevice = new InfoMediaDevice(mContext, info);
        mInfoMediaManager.mMediaDevices.add(infoDevice);

        final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID);
        assertThat(mediaDevice).isNotNull();
        assertThat(mInfoMediaManager.mMediaDevices).hasSize(1);

        mInfoMediaManager.mMediaRouterCallback.onRouteRemoved(mMediaRouter, info);

        assertThat(mInfoMediaManager.mMediaDevices).isEmpty();
    }

    @Test
    public void onRouteRemoved_mediaDeviceNotExistInList_doNothing() {
        final MediaRouter.RouteInfo info = mock(MediaRouter.RouteInfo.class);
        when(info.getId()).thenReturn(TEST_ID);

        final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID);
        final int size = mInfoMediaManager.mMediaDevices.size();
        assertThat(mediaDevice).isNull();

        mInfoMediaManager.mMediaRouterCallback.onRouteRemoved(mMediaRouter, info);

        assertThat(mInfoMediaManager.mMediaDevices).hasSize(size);
    }
}
+369 −0

File added.

Preview size limit exceeded, changes collapsed.

+67 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading