DeviceNamePreferenceControllerTest converted to JUnit

Rather than mocking the PreferenceScreen's getPreference function,
a PreferenceManager has been created, which instantiates the Screen.
The desired Preference is added to the Screen with the testing key.
Rather than using a shadow XML, contexts' resources are mocked.
A mock WifiManager is used instead of a shadow
Duplicate test case removed, and test which succeeds locally but
not on cuttlefish marked as ignored for now.


Bug: 175389659
Test: atest -c DeviceNamePreferenceControllerTest
Change-Id: I643b22993a1d102614fed1883af7f4925947be20
This commit is contained in:
Jeremy Goldman
2020-12-18 18:54:57 +08:00
parent 04eeb1e5e3
commit 6625f03eca
2 changed files with 40 additions and 25 deletions

View File

@@ -25,6 +25,7 @@ import android.os.Bundle;
import android.provider.Settings;
import android.text.SpannedString;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -44,6 +45,8 @@ public class DeviceNamePreferenceController extends BasePreferenceController
OnSaveInstanceState,
OnCreate {
private static final String KEY_PENDING_DEVICE_NAME = "key_pending_device_name";
@VisibleForTesting
static final int RES_SHOW_DEVICE_NAME_BOOL = R.bool.config_show_device_name;
private String mDeviceName;
protected WifiManager mWifiManager;
private final BluetoothAdapter mBluetoothAdapter;