blob: 30a6ad2576dbfebcf645618ac1af46af098c3208 [file] [log] [blame]
hughchen61c1c9f2019-01-17 14:34:51 +08001/*
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
17package com.android.settingslib.media;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import static org.mockito.Mockito.when;
22
hughchen2a3151d2019-03-20 14:46:12 +080023import android.bluetooth.BluetoothDevice;
hughchene6a4f482019-10-18 17:34:15 +080024import android.media.MediaRoute2Info;
hughchen61c1c9f2019-01-17 14:34:51 +080025
26import com.android.settingslib.bluetooth.CachedBluetoothDevice;
27
28import org.junit.Before;
29import org.junit.Test;
30import org.junit.runner.RunWith;
31import org.mockito.Mock;
32import org.mockito.MockitoAnnotations;
33import org.robolectric.RobolectricTestRunner;
34
35@RunWith(RobolectricTestRunner.class)
36public 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
hughchen2a3151d2019-03-20 14:46:12 +080042 private CachedBluetoothDevice mCachedDevice;
43 @Mock
44 private BluetoothDevice mBluetoothDevice;
hughchen61c1c9f2019-01-17 14:34:51 +080045 @Mock
hughchene6a4f482019-10-18 17:34:15 +080046 private MediaRoute2Info mRouteInfo;
hughchen61c1c9f2019-01-17 14:34:51 +080047
48 @Before
49 public void setUp() {
50 MockitoAnnotations.initMocks(this);
51 }
52
53 @Test
hughchen2a3151d2019-03-20 14:46:12 +080054 public void getId_returnCachedBluetoothDeviceAddress() {
55 when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
hughchen61c1c9f2019-01-17 14:34:51 +080056
hughchen2a3151d2019-03-20 14:46:12 +080057 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);
hughchen61c1c9f2019-01-17 14:34:51 +080067
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}