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 32 @RunWith(RobolectricTestRunner.class) 33 public class BluetoothFeatureProviderImplTest { 34 private static final String SETTINGS_URI = "content://test.provider/settings_uri"; 35 private static final String CONTROL_METADATA = 36 "<HEARABLE_CONTROL_SLICE_WITH_WIDTH>" + SETTINGS_URI 37 + "</HEARABLE_CONTROL_SLICE_WITH_WIDTH>"; 38 private static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25; 39 40 private BluetoothFeatureProvider mBluetoothFeatureProvider; 41 42 @Mock 43 private BluetoothDevice mBluetoothDevice; 44 45 @Before setUp()46 public void setUp() { 47 MockitoAnnotations.initMocks(this); 48 49 mBluetoothFeatureProvider = new BluetoothFeatureProviderImpl(); 50 } 51 52 @Test getBluetoothDeviceSettingsUri_containCorrectMacAddress()53 public void getBluetoothDeviceSettingsUri_containCorrectMacAddress() { 54 when(mBluetoothDevice.getMetadata( 55 BluetoothDevice.METADATA_ENHANCED_SETTINGS_UI_URI)).thenReturn( 56 SETTINGS_URI.getBytes()); 57 final Uri uri = mBluetoothFeatureProvider.getBluetoothDeviceSettingsUri(mBluetoothDevice); 58 assertThat(uri.toString()).isEqualTo(SETTINGS_URI); 59 } 60 61 @Test getBluetoothDeviceControlUri_returnsCorrectUri()62 public void getBluetoothDeviceControlUri_returnsCorrectUri() { 63 when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS)).thenReturn( 64 CONTROL_METADATA.getBytes()); 65 assertThat( 66 mBluetoothFeatureProvider.getBluetoothDeviceControlUri(mBluetoothDevice)).isEqualTo( 67 SETTINGS_URI); 68 } 69 } 70