Files
app_Settings/tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingDialogTest.java
Haijie Hong f93aaadad0 Show a dialog if bluetooth key is missing when reconnecting
Previous change is reverted due to test failure in b/362901443.

BUG: 360031750
Test: atest BluetoothKeyMissingDialogTest
Flag: com.android.settings.flags.enable_bluetooth_key_missing_dialog
Change-Id: I05b940e8aac26c14f93baa19c224ad98c291b891
2024-09-04 09:05:08 +00:00

77 lines
2.5 KiB
Java

/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
import android.bluetooth.BluetoothDevice;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowAlertDialogCompat.class)
public class BluetoothKeyMissingDialogTest {
@Mock private BluetoothDevice mBluetoothDevice;
private BluetoothKeyMissingDialogFragment mFragment = null;
private FragmentActivity mActivity = null;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mActivity = Robolectric.setupActivity(FragmentActivity.class);
mFragment = new BluetoothKeyMissingDialogFragment(mBluetoothDevice);
mActivity
.getSupportFragmentManager()
.beginTransaction()
.add(mFragment, null)
.commit();
shadowMainLooper().idle();
}
@Test
public void clickForgetDevice_removeBond() {
mFragment.onClick(mFragment.getDialog(), AlertDialog.BUTTON_POSITIVE);
verify(mBluetoothDevice).removeBond();
assertThat(mActivity.isFinishing()).isTrue();
}
@Test
public void clickCancel_notRemoveBond() {
mFragment.onClick(mFragment.getDialog(), AlertDialog.BUTTON_NEGATIVE);
verify(mBluetoothDevice, never()).removeBond();
assertThat(mActivity.isFinishing()).isTrue();
}
}