hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settingslib.media; |
| 18 | |
| 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
| 21 | import static org.mockito.Mockito.when; |
| 22 | |
hughchen | 2a3151d | 2019-03-20 14:46:12 +0800 | [diff] [blame] | 23 | import android.bluetooth.BluetoothDevice; |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 24 | import android.media.MediaRoute2Info; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 25 | |
| 26 | import com.android.settingslib.bluetooth.CachedBluetoothDevice; |
| 27 | |
| 28 | import org.junit.Before; |
| 29 | import org.junit.Test; |
| 30 | import org.junit.runner.RunWith; |
| 31 | import org.mockito.Mock; |
| 32 | import org.mockito.MockitoAnnotations; |
| 33 | import org.robolectric.RobolectricTestRunner; |
| 34 | |
| 35 | @RunWith(RobolectricTestRunner.class) |
| 36 | public class MediaDeviceUtilsTest { |
| 37 | |
| 38 | private static final String TEST_ADDRESS = "11:22:33:44:55:66"; |
| 39 | private static final String TEST_ROUTE_ID = "test_route_id"; |
| 40 | |
| 41 | @Mock |
hughchen | 2a3151d | 2019-03-20 14:46:12 +0800 | [diff] [blame] | 42 | private CachedBluetoothDevice mCachedDevice; |
| 43 | @Mock |
| 44 | private BluetoothDevice mBluetoothDevice; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 45 | @Mock |
hughchen | e6a4f48 | 2019-10-18 17:34:15 +0800 | [diff] [blame] | 46 | private MediaRoute2Info mRouteInfo; |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 47 | |
| 48 | @Before |
| 49 | public void setUp() { |
| 50 | MockitoAnnotations.initMocks(this); |
| 51 | } |
| 52 | |
| 53 | @Test |
hughchen | 2a3151d | 2019-03-20 14:46:12 +0800 | [diff] [blame] | 54 | public void getId_returnCachedBluetoothDeviceAddress() { |
| 55 | when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 56 | |
hughchen | 2a3151d | 2019-03-20 14:46:12 +0800 | [diff] [blame] | 57 | final String id = MediaDeviceUtils.getId(mCachedDevice); |
| 58 | |
| 59 | assertThat(id).isEqualTo(TEST_ADDRESS); |
| 60 | } |
| 61 | |
| 62 | @Test |
| 63 | public void getId_returnBluetoothDeviceAddress() { |
| 64 | when(mBluetoothDevice.getAddress()).thenReturn(TEST_ADDRESS); |
| 65 | |
| 66 | final String id = MediaDeviceUtils.getId(mBluetoothDevice); |
hughchen | 61c1c9f | 2019-01-17 14:34:51 +0800 | [diff] [blame] | 67 | |
| 68 | assertThat(id).isEqualTo(TEST_ADDRESS); |
| 69 | } |
| 70 | |
| 71 | @Test |
| 72 | public void getId_returnRouteInfoId() { |
| 73 | when(mRouteInfo.getId()).thenReturn(TEST_ROUTE_ID); |
| 74 | |
| 75 | final String id = MediaDeviceUtils.getId(mRouteInfo); |
| 76 | |
| 77 | assertThat(id).isEqualTo(TEST_ROUTE_ID); |
| 78 | } |
| 79 | } |