Fix AccessibilityHearingAidPreferenceControllerTest

**Root cause**
When adding a feature flag on showing different hearing aid page on
 click, the tests were not executed because they were marked as @Ignore.

In order to execute the test, we need to turn the feature flag off, so that the test run in the same scenario where the feature flag was not introduced.

Bug: 279082331
Test: atest AccessibilityHearingAidPreferenceControllerTest
Change-Id: If11ac40a7ea3926578992f7c0577e7cbb1bb3273
This commit is contained in:
Chun-Ku Lin
2023-06-02 06:26:30 +00:00
parent 8517a41908
commit 0aea3ddb33

View File

@@ -18,12 +18,15 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.app.Application;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHapClient;
@@ -32,6 +35,7 @@ import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.FeatureFlagUtils;
import androidx.preference.Preference;
import androidx.test.core.app.ApplicationProvider;
@@ -107,7 +111,9 @@ public class AccessibilityHearingAidPreferenceControllerTest {
@Before
public void setUp() {
mShadowApplication = ShadowApplication.getInstance();
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_HEARING_AID_PAGE, true);
mShadowApplication = shadowOf((Application) ApplicationProvider.getApplicationContext());
setupEnvironment();
mHearingAidPreference = new Preference(mContext);
@@ -247,10 +253,13 @@ public class AccessibilityHearingAidPreferenceControllerTest {
@Test
public void handleHearingAidPreferenceClick_noHearingAid_launchHearingAidInstructionDialog() {
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_HEARING_AID_PAGE, false);
mPreferenceController = spy(new AccessibilityHearingAidPreferenceController(mContext,
HEARING_AID_PREFERENCE));
mPreferenceController.setPreference(mHearingAidPreference);
doNothing().when(mPreferenceController).launchHearingAidInstructionDialog();
mPreferenceController.handlePreferenceTreeClick(mHearingAidPreference);
verify(mPreferenceController).launchHearingAidInstructionDialog();
@@ -259,11 +268,15 @@ public class AccessibilityHearingAidPreferenceControllerTest {
@Test
public void handleHearingAidPreferenceClick_withHearingAid_launchBluetoothDeviceDetailSetting
() {
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_HEARING_AID_PAGE, false);
mPreferenceController = spy(new AccessibilityHearingAidPreferenceController(mContext,
HEARING_AID_PREFERENCE));
mPreferenceController.setPreference(mHearingAidPreference);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
doNothing().when(mPreferenceController).launchBluetoothDeviceDetailSetting(any());
mPreferenceController.handlePreferenceTreeClick(mHearingAidPreference);
verify(mPreferenceController).launchBluetoothDeviceDetailSetting(mCachedBluetoothDevice);