Update StorageSummaryDonutPrefCtrl test to sdk 26
Test: make RunSettingsRoboTests -j40 Change-Id: I9389254b94452e3f23b964225445435f2384901d
This commit is contained in:
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.format.Formatter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
@@ -56,11 +57,11 @@ import static com.android.settings.TestUtils.KILOBYTE;
|
||||
import static com.android.settings.TestUtils.GIGABYTE;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class
|
||||
})
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class
|
||||
})
|
||||
public class StorageSummaryDonutPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private StorageSummaryDonutPreferenceController mController;
|
||||
@@ -94,43 +95,62 @@ public class StorageSummaryDonutPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testEmpty() throws Exception {
|
||||
final long totalSpace = 32 * GIGABYTE;
|
||||
final long usedSpace = 0;
|
||||
mController.updateBytes(0, 32 * GIGABYTE);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getTitle().toString()).isEqualTo("0.00 B");
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 32 GB");
|
||||
final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
|
||||
mContext.getResources(), usedSpace, 0 /* flags */);
|
||||
assertThat(mPreference.getTitle().toString()).isEqualTo(
|
||||
usedSpaceResults.value + " " + usedSpaceResults.units);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||
"Used of " + Formatter.formatShortFileSize(mContext, totalSpace));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTotalStorage() throws Exception {
|
||||
mController.updateBytes(KILOBYTE, KILOBYTE * 10);
|
||||
final long totalSpace = KILOBYTE * 10;
|
||||
final long usedSpace = KILOBYTE;
|
||||
mController.updateBytes(KILOBYTE, totalSpace);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getTitle().toString()).isEqualTo("1.00 KB");
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
|
||||
final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
|
||||
mContext.getResources(), usedSpace, 0 /* flags */);
|
||||
assertThat(mPreference.getTitle().toString()).isEqualTo(
|
||||
usedSpaceResults.value + " " + usedSpaceResults.units);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||
"Used of " + Formatter.formatShortFileSize(mContext, totalSpace));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulateWithVolume() throws Exception {
|
||||
VolumeInfo volume = Mockito.mock(VolumeInfo.class);
|
||||
File file = Mockito.mock(File.class);
|
||||
StorageVolumeProvider svp = Mockito.mock(StorageVolumeProvider.class);
|
||||
final long totalSpace = KILOBYTE * 10;
|
||||
final long freeSpace = KILOBYTE;
|
||||
final long usedSpace = totalSpace - freeSpace;
|
||||
final VolumeInfo volume = Mockito.mock(VolumeInfo.class);
|
||||
final File file = Mockito.mock(File.class);
|
||||
final StorageVolumeProvider svp = Mockito.mock(StorageVolumeProvider.class);
|
||||
when(volume.getPath()).thenReturn(file);
|
||||
when(file.getTotalSpace()).thenReturn(KILOBYTE * 10);
|
||||
when(file.getFreeSpace()).thenReturn(KILOBYTE);
|
||||
when(svp.getPrimaryStorageSize()).thenReturn(KILOBYTE * 10);
|
||||
when(file.getTotalSpace()).thenReturn(totalSpace);
|
||||
when(file.getFreeSpace()).thenReturn(freeSpace);
|
||||
when(svp.getPrimaryStorageSize()).thenReturn(totalSpace);
|
||||
|
||||
mController.updateSizes(svp, volume);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getTitle().toString()).isEqualTo("9.00 KB");
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
|
||||
final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
|
||||
mContext.getResources(), usedSpace, 0 /* flags */);
|
||||
assertThat(mPreference.getTitle().toString()).isEqualTo(
|
||||
usedSpaceResults.value + " " + usedSpaceResults.units);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||
"Used of " + Formatter.formatShortFileSize(mContext, totalSpace));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFreeUpSpaceMetricIsTriggered() throws Exception {
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
Button button = (Button) mHolder.findViewById(R.id.deletion_helper_button);
|
||||
final Button button = (Button) mHolder.findViewById(R.id.deletion_helper_button);
|
||||
|
||||
mPreference.onClick(button);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user