Use Builder to replace the Uitls.addFooterPreference

Fixes: 139163212
Test: manual test
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.bluetooth
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.accounts
Change-Id: I861434b81c07db785e6f1cfb3e34871ffba41e5f
This commit is contained in:
Sunny Shao
2019-08-09 11:42:04 +08:00
parent 7be752269b
commit 7e866b670e
5 changed files with 113 additions and 169 deletions

View File

@@ -15,8 +15,6 @@
*/
package com.android.settings.accounts;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -26,9 +24,7 @@ import android.content.Context;
import android.os.UserHandle;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import com.android.settings.testutils.shadow.ShadowAuthenticationHelper;
import com.android.settings.testutils.shadow.ShadowContentResolver;
import org.junit.After;
@@ -37,7 +33,6 @@ import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.androidx.fragment.FragmentController;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
@@ -62,18 +57,4 @@ public class AccountSyncSettingsTest {
settings.onPreferenceTreeClick(preference);
// no crash
}
@Test
@Config(shadows = {ShadowAuthenticationHelper.class})
public void createFooterPreference_shouldReturnFooter() {
final AccountSyncSettings settings = FragmentController.of(new AccountSyncSettings())
.create()
.get();
settings.createFooterPreference();
final Preference footer = settings.getPreferenceScreen().findPreference(
"footer_preference");
assertThat(footer).isNotNull();
}
}

View File

@@ -19,7 +19,6 @@ import static com.android.settings.bluetooth.BluetoothDetailsMacAddressControlle
import static com.google.common.truth.Truth.assertThat;
import com.android.settings.Utils;
import com.android.settingslib.widget.FooterPreference;
import org.junit.Test;
@@ -28,22 +27,24 @@ import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class BluetoothDetailsMacAddressControllerTest extends BluetoothDetailsControllerTestBase {
private BluetoothDetailsMacAddressController mController;
private BluetoothDetailsMacAddressController mController;
@Override
public void setUp() {
super.setUp();
mController =
new BluetoothDetailsMacAddressController(mContext, mFragment, mCachedDevice, mLifecycle);
setupDevice(mDeviceConfig);
Utils.addFooterPreference(mContext, mScreen, KEY_DEVICE_DETAILS_FOOTER, null /* title */);
}
@Override
public void setUp() {
super.setUp();
mController =
new BluetoothDetailsMacAddressController(mContext, mFragment, mCachedDevice,
mLifecycle);
setupDevice(mDeviceConfig);
mScreen.addPreference(new FooterPreference.Builder(mContext).setKey(
KEY_DEVICE_DETAILS_FOOTER).build());
}
@Test
public void macAddress() {
showScreen(mController);
FooterPreference footer =
(FooterPreference) mScreen.findPreference(mController.getPreferenceKey());
assertThat(footer.getTitle().toString()).endsWith(mDeviceConfig.getAddress());
}
@Test
public void macAddress() {
showScreen(mController);
FooterPreference footer =
(FooterPreference) mScreen.findPreference(mController.getPreferenceKey());
assertThat(footer.getTitle().toString()).endsWith(mDeviceConfig.getAddress());
}
}