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 android.bluetooth.BluetoothDevice.PAIRING_VARIANT_CONSENT; 19 20 import static org.mockito.Mockito.spy; 21 import static org.mockito.Mockito.verify; 22 23 import android.bluetooth.BluetoothDevice; 24 import android.content.Context; 25 import android.content.Intent; 26 27 import com.android.settings.testutils.SettingsRobolectricTestRunner; 28 import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; 29 import com.android.settings.testutils.shadow.ShadowBluetoothPan; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.mockito.Mock; 35 import org.mockito.MockitoAnnotations; 36 import org.robolectric.RuntimeEnvironment; 37 import org.robolectric.annotation.Config; 38 39 @RunWith(SettingsRobolectricTestRunner.class) 40 @Config(shadows = {ShadowBluetoothPan.class, ShadowBluetoothAdapter.class}) 41 public class BluetoothPairingControllerTest { 42 @Mock 43 private BluetoothDevice mBluetoothDevice; 44 private Context mContext; 45 private BluetoothPairingController mBluetoothPairingController; 46 47 @Before setUp()48 public void setUp() { 49 MockitoAnnotations.initMocks(this); 50 51 mContext = RuntimeEnvironment.application; 52 final Intent intent = new Intent(); 53 intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); 54 mBluetoothPairingController = spy(new BluetoothPairingController(intent, mContext)); 55 } 56 57 @Test onDialogPositiveClick_confirmationDialog_setPBAP()58 public void onDialogPositiveClick_confirmationDialog_setPBAP() { 59 mBluetoothPairingController.mType = PAIRING_VARIANT_CONSENT; 60 mBluetoothPairingController.onCheckedChanged(null, true); 61 62 mBluetoothPairingController.onDialogPositiveClick(null); 63 64 verify(mBluetoothDevice).setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED); 65 } 66 } 67