Files
app_Settings/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHearingDeviceSettingsControllerTest.java
jasonwshsu 9cfc96d948 Show intro and footer string according to the device's supported status
Bug: 390078046
Bug: 386121967
Test: atest HearingAidHelperTest HearingDeviceFooterPreferenceControllerTest HearingDeviceIntroPreferenceControllerTest BluetoothDetailsHearingDeviceSettingsControllerTest
Flag: EXEMPT bugfix
Change-Id: I564cdb80cd14f4d2d8e882b64db939449c6936b7
Signed-off-by: Jie Wang <jie.x.wang@sony.com>
Signed-off-by: Jason Hsu <jasonwshsu@google.com>
2025-02-11 17:26:37 +08:00

97 lines
3.3 KiB
Java

/*
* Copyright (C) 2022 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.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import androidx.preference.Preference;
import com.android.settings.SettingsActivity;
import com.android.settings.accessibility.AccessibilityHearingAidsFragment;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link BluetoothDetailsHearingDeviceSettingsController}. */
@RunWith(RobolectricTestRunner.class)
public class BluetoothDetailsHearingDeviceSettingsControllerTest extends
BluetoothDetailsControllerTestBase {
@Rule
public final MockitoRule mockito = MockitoJUnit.rule();
@Captor
private ArgumentCaptor<Intent> mIntentArgumentCaptor;
private BluetoothDetailsHearingDeviceSettingsController mController;
@Override
public void setUp() {
super.setUp();
FakeFeatureFactory.setupForTest();
mController = new BluetoothDetailsHearingDeviceSettingsController(mActivity, mFragment,
mCachedDevice, mLifecycle);
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
}
@Test
public void isAvailable_isHearingDevice_available() {
when(mCachedDevice.isHearingDevice()).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_isNotHearingDevice_notAvailable() {
when(mCachedDevice.isHearingDevice()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void onPreferenceClick_hearingDeviceSettingsKey_launchExpectedFragment() {
final Preference hearingDeviceSettingsPreference = new Preference(mContext);
hearingDeviceSettingsPreference.setKey(
BluetoothDetailsHearingDeviceSettingsController.KEY_HEARING_DEVICE_SETTINGS);
mController.onPreferenceClick(hearingDeviceSettingsPreference);
assertStartActivityWithExpectedFragment(mActivity,
AccessibilityHearingAidsFragment.class.getName());
}
private void assertStartActivityWithExpectedFragment(Context mockContext, String fragmentName) {
verify(mockContext).startActivity(mIntentArgumentCaptor.capture());
assertThat(mIntentArgumentCaptor.getValue()
.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
.isEqualTo(fragmentName);
}
}