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.content.Context;
|
||||||
import android.os.storage.VolumeInfo;
|
import android.os.storage.VolumeInfo;
|
||||||
import android.support.v7.preference.PreferenceViewHolder;
|
import android.support.v7.preference.PreferenceViewHolder;
|
||||||
|
import android.text.format.Formatter;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -56,11 +57,11 @@ import static com.android.settings.TestUtils.KILOBYTE;
|
|||||||
import static com.android.settings.TestUtils.GIGABYTE;
|
import static com.android.settings.TestUtils.GIGABYTE;
|
||||||
|
|
||||||
@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,
|
||||||
shadows = {
|
shadows = {
|
||||||
SettingsShadowResources.class,
|
SettingsShadowResources.class,
|
||||||
SettingsShadowResources.SettingsShadowTheme.class
|
SettingsShadowResources.SettingsShadowTheme.class
|
||||||
})
|
})
|
||||||
public class StorageSummaryDonutPreferenceControllerTest {
|
public class StorageSummaryDonutPreferenceControllerTest {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private StorageSummaryDonutPreferenceController mController;
|
private StorageSummaryDonutPreferenceController mController;
|
||||||
@@ -94,43 +95,62 @@ public class StorageSummaryDonutPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmpty() throws Exception {
|
public void testEmpty() throws Exception {
|
||||||
|
final long totalSpace = 32 * GIGABYTE;
|
||||||
|
final long usedSpace = 0;
|
||||||
mController.updateBytes(0, 32 * GIGABYTE);
|
mController.updateBytes(0, 32 * GIGABYTE);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.getTitle().toString()).isEqualTo("0.00 B");
|
final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
|
||||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 32 GB");
|
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
|
@Test
|
||||||
public void testTotalStorage() throws Exception {
|
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);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.getTitle().toString()).isEqualTo("1.00 KB");
|
final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
|
||||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
|
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
|
@Test
|
||||||
public void testPopulateWithVolume() throws Exception {
|
public void testPopulateWithVolume() throws Exception {
|
||||||
VolumeInfo volume = Mockito.mock(VolumeInfo.class);
|
final long totalSpace = KILOBYTE * 10;
|
||||||
File file = Mockito.mock(File.class);
|
final long freeSpace = KILOBYTE;
|
||||||
StorageVolumeProvider svp = Mockito.mock(StorageVolumeProvider.class);
|
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(volume.getPath()).thenReturn(file);
|
||||||
when(file.getTotalSpace()).thenReturn(KILOBYTE * 10);
|
when(file.getTotalSpace()).thenReturn(totalSpace);
|
||||||
when(file.getFreeSpace()).thenReturn(KILOBYTE);
|
when(file.getFreeSpace()).thenReturn(freeSpace);
|
||||||
when(svp.getPrimaryStorageSize()).thenReturn(KILOBYTE * 10);
|
when(svp.getPrimaryStorageSize()).thenReturn(totalSpace);
|
||||||
|
|
||||||
mController.updateSizes(svp, volume);
|
mController.updateSizes(svp, volume);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.getTitle().toString()).isEqualTo("9.00 KB");
|
final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
|
||||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
|
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
|
@Test
|
||||||
public void testFreeUpSpaceMetricIsTriggered() throws Exception {
|
public void testFreeUpSpaceMetricIsTriggered() throws Exception {
|
||||||
mPreference.onBindViewHolder(mHolder);
|
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);
|
mPreference.onClick(button);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user