Update UserProfileControllerTest to sdk 26
Test: make RunSettingsRoboTests -j40 Change-Id: Ia0f654fd54e43b0fdba3077f7df178faaa314b3d
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.settings.deviceinfo.storage;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
|
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -53,7 +54,7 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||||
public class UserProfileControllerTest {
|
public class UserProfileControllerTest {
|
||||||
private static final String TEST_NAME = "Fred";
|
private static final String TEST_NAME = "Fred";
|
||||||
|
|
||||||
@@ -82,7 +83,7 @@ public class UserProfileControllerTest {
|
|||||||
public void controllerAddsPrimaryProfilePreference() throws Exception {
|
public void controllerAddsPrimaryProfilePreference() throws Exception {
|
||||||
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
|
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
|
||||||
verify(mScreen).addPreference(argumentCaptor.capture());
|
verify(mScreen).addPreference(argumentCaptor.capture());
|
||||||
Preference preference = argumentCaptor.getValue();
|
final Preference preference = argumentCaptor.getValue();
|
||||||
|
|
||||||
assertThat(preference.getTitle()).isEqualTo(TEST_NAME);
|
assertThat(preference.getTitle()).isEqualTo(TEST_NAME);
|
||||||
assertThat(preference.getKey()).isEqualTo("pref_profile_10");
|
assertThat(preference.getKey()).isEqualTo("pref_profile_10");
|
||||||
@@ -93,12 +94,12 @@ public class UserProfileControllerTest {
|
|||||||
|
|
||||||
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
|
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
|
||||||
verify(mScreen).addPreference(argumentCaptor.capture());
|
verify(mScreen).addPreference(argumentCaptor.capture());
|
||||||
Preference preference = argumentCaptor.getValue();
|
final Preference preference = argumentCaptor.getValue();
|
||||||
assertThat(mController.handlePreferenceTreeClick(preference)).isTrue();
|
assertThat(mController.handlePreferenceTreeClick(preference)).isTrue();
|
||||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
verify(mContext).startActivity(intentCaptor.capture());
|
verify(mContext).startActivity(intentCaptor.capture());
|
||||||
|
|
||||||
Intent intent = intentCaptor.getValue();
|
final Intent intent = intentCaptor.getValue();
|
||||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
|
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
|
||||||
StorageProfileFragment.class.getName());
|
StorageProfileFragment.class.getName());
|
||||||
@@ -106,8 +107,8 @@ public class UserProfileControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void acceptingResultUpdatesPreferenceSize() throws Exception {
|
public void acceptingResultUpdatesPreferenceSize() throws Exception {
|
||||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
|
final SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
|
||||||
StorageAsyncLoader.AppsStorageResult userResult =
|
final StorageAsyncLoader.AppsStorageResult userResult =
|
||||||
new StorageAsyncLoader.AppsStorageResult();
|
new StorageAsyncLoader.AppsStorageResult();
|
||||||
userResult.externalStats =
|
userResult.externalStats =
|
||||||
new StorageStatsSource.ExternalStorageStats(
|
new StorageStatsSource.ExternalStorageStats(
|
||||||
@@ -120,25 +121,23 @@ public class UserProfileControllerTest {
|
|||||||
mController.handleResult(result);
|
mController.handleResult(result);
|
||||||
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
|
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
|
||||||
verify(mScreen).addPreference(argumentCaptor.capture());
|
verify(mScreen).addPreference(argumentCaptor.capture());
|
||||||
Preference preference = argumentCaptor.getValue();
|
final Preference preference = argumentCaptor.getValue();
|
||||||
|
|
||||||
assertThat(preference.getSummary()).isEqualTo("0.10 GB");
|
assertThat(preference.getSummary()).isEqualTo("0.10 GB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void iconCallbackChangesPreferenceIcon() throws Exception {
|
public void iconCallbackChangesPreferenceIcon() throws Exception {
|
||||||
SparseArray<Drawable> icons = new SparseArray<>();
|
final SparseArray<Drawable> icons = new SparseArray<>();
|
||||||
Bitmap userBitmap =
|
final UserIconDrawable drawable = mock(UserIconDrawable.class);
|
||||||
BitmapFactory.decodeResource(
|
when(drawable.mutate()).thenReturn(drawable);
|
||||||
RuntimeEnvironment.application.getResources(), R.drawable.home);
|
icons.put(mPrimaryProfile.id, drawable);
|
||||||
UserIconDrawable drawable = new UserIconDrawable(100 /* size */).setIcon(userBitmap).bake();
|
|
||||||
icons.put(10, drawable);
|
|
||||||
|
|
||||||
mController.handleUserIcons(icons);
|
mController.handleUserIcons(icons);
|
||||||
|
|
||||||
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
|
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
|
||||||
verify(mScreen).addPreference(argumentCaptor.capture());
|
verify(mScreen).addPreference(argumentCaptor.capture());
|
||||||
Preference preference = argumentCaptor.getValue();
|
final Preference preference = argumentCaptor.getValue();
|
||||||
assertThat(preference.getIcon()).isEqualTo(drawable);
|
assertThat(preference.getIcon()).isEqualTo(drawable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user