• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 package com.android.settings.bluetooth;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import static org.mockito.Mockito.when;
21 
22 import android.bluetooth.BluetoothDevice;
23 import android.net.Uri;
24 
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.Mock;
29 import org.mockito.MockitoAnnotations;
30 import org.robolectric.RobolectricTestRunner;
31 import org.robolectric.RuntimeEnvironment;
32 
33 @RunWith(RobolectricTestRunner.class)
34 public class BluetoothFeatureProviderImplTest {
35     private static final String SETTINGS_URI = "content://test.provider/settings_uri";
36     private static final String CONTROL_METADATA =
37             "<HEARABLE_CONTROL_SLICE_WITH_WIDTH>" + SETTINGS_URI
38                     + "</HEARABLE_CONTROL_SLICE_WITH_WIDTH>";
39     private static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25;
40 
41     private BluetoothFeatureProvider mBluetoothFeatureProvider;
42 
43     @Mock
44     private BluetoothDevice mBluetoothDevice;
45 
46     @Before
setUp()47     public void setUp() {
48         MockitoAnnotations.initMocks(this);
49 
50         mBluetoothFeatureProvider = new BluetoothFeatureProviderImpl(
51                 RuntimeEnvironment.application);
52     }
53 
54     @Test
getBluetoothDeviceSettingsUri_containCorrectMacAddress()55     public void getBluetoothDeviceSettingsUri_containCorrectMacAddress() {
56         when(mBluetoothDevice.getMetadata(
57                 BluetoothDevice.METADATA_ENHANCED_SETTINGS_UI_URI)).thenReturn(
58                 SETTINGS_URI.getBytes());
59         final Uri uri = mBluetoothFeatureProvider.getBluetoothDeviceSettingsUri(mBluetoothDevice);
60         assertThat(uri.toString()).isEqualTo(SETTINGS_URI);
61     }
62 
63     @Test
getBluetoothDeviceControlUri_returnsCorrectUri()64     public void getBluetoothDeviceControlUri_returnsCorrectUri() {
65         when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS)).thenReturn(
66                 CONTROL_METADATA.getBytes());
67         assertThat(
68                 mBluetoothFeatureProvider.getBluetoothDeviceControlUri(mBluetoothDevice)).isEqualTo(
69                 SETTINGS_URI);
70     }
71 }
72