Merge "Revert "Don't use framework strings for formatting file sizes""

This commit is contained in:
Victor Chang
2018-01-04 17:35:19 +00:00
committed by Android (Google) Code Review
7 changed files with 45 additions and 92 deletions

View File

@@ -92,6 +92,8 @@ public class StorageItemPreferenceControllerTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
SettingsShadowResources.overrideResource("android:string/fileSizeSuffix", "%1$s %2$s");
SettingsShadowResources.overrideResource("android:string/gigabyteShort", "GB");
when(mFragment.getActivity()).thenReturn(mActivity);
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);

View File

@@ -1,8 +1,8 @@
To build the tests you can use the following command at the root of your android source tree
$ make -j SettingsUnitTests
$ make SettingsUnitTests
The test apk then needs to be installed onto your test device via for example
$ adb install -r ${ANDROID_PRODUCT_OUT}/data/app/SettingsUnitTests/SettingsUnitTests.apk
$ adb install -r out/target/product/shamu/data/app/SettingsUnitTests/SettingsUnitTests.apk
To run all tests:
$ adb shell am instrument -w com.android.settings.tests.unit/android.support.test.runner.AndroidJUnitRunner

View File

@@ -22,7 +22,6 @@ import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.icu.util.MeasureUnit;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
@@ -47,7 +46,7 @@ public class FileSizeFormatterTest {
FileSizeFormatter.formatFileSize(
mContext,
0 /* size */,
MeasureUnit.GIGABYTE,
com.android.internal.R.string.gigabyteShort,
GIGABYTE_IN_BYTES))
.isEqualTo("0.00 GB");
}
@@ -58,7 +57,7 @@ public class FileSizeFormatterTest {
FileSizeFormatter.formatFileSize(
mContext,
MEGABYTE_IN_BYTES * 11 /* size */,
MeasureUnit.GIGABYTE,
com.android.internal.R.string.gigabyteShort,
GIGABYTE_IN_BYTES))
.isEqualTo("0.01 GB");
}
@@ -69,7 +68,7 @@ public class FileSizeFormatterTest {
FileSizeFormatter.formatFileSize(
mContext,
MEGABYTE_IN_BYTES * 155 /* size */,
MeasureUnit.GIGABYTE,
com.android.internal.R.string.gigabyteShort,
GIGABYTE_IN_BYTES))
.isEqualTo("0.16 GB");
}
@@ -80,7 +79,7 @@ public class FileSizeFormatterTest {
FileSizeFormatter.formatFileSize(
mContext,
MEGABYTE_IN_BYTES * 1551 /* size */,
MeasureUnit.GIGABYTE,
com.android.internal.R.string.gigabyteShort,
GIGABYTE_IN_BYTES))
.isEqualTo("1.6 GB");
}
@@ -92,7 +91,7 @@ public class FileSizeFormatterTest {
FileSizeFormatter.formatFileSize(
mContext,
GIGABYTE_IN_BYTES * 15 + MEGABYTE_IN_BYTES * 50 /* size */,
MeasureUnit.GIGABYTE,
com.android.internal.R.string.gigabyteShort,
GIGABYTE_IN_BYTES))
.isEqualTo("15 GB");
}
@@ -103,7 +102,7 @@ public class FileSizeFormatterTest {
FileSizeFormatter.formatFileSize(
mContext,
MEGABYTE_IN_BYTES * -155 /* size */,
MeasureUnit.GIGABYTE,
com.android.internal.R.string.gigabyteShort,
GIGABYTE_IN_BYTES))
.isEqualTo("-0.16 GB");
}