MountPointUtils { @NonNull public static String formatStorageSize(Context context, long storageSize) { String storageSuffix = "b"; float formatedStorageSize = storageSize; if (formatedStorageSize >= 1024) { storageSuffix = "kb"; formatedStorageSize /= 1024f; if (formatedStorageSize >= 1024) { storageSuffix = "mb"; formatedStorageSize /= 1024f; if (formatedStorageSize >= 1024) { storageSuffix = "gb"; formatedStorageSize /= 1024f; } } } int stringResource = context.getResources() .getIdentifier("storage_size_" + storageSuffix, "string", context.getPackageName()); if (stringResource == 0) { return context.getString(R.string.storage_size_kb, storageSize / 1024f); } return context.getString(stringResource, formatedStorageSize); }  @NonNull static MountPoint getInternalStorage(); @Nullable static MountPoint getExternalStorage(@NonNull final Context context,
                                                @Nullable String... storageStates); @NonNull static List<MountPoint> getMountPoints(@NonNull final Context context); static boolean isMounted(@NonNull final MountPoint mountPoint); @NonNull static String formatStorageSize(Context context,
                                           long storageSize); @NonNull static String formatStorageStatus(Context context,
                                             @NonNull final String status);  }
@Test public void testFormatStorageSize() { long storageInB = 128L; final String storageInBFormatted = formatStorageSize(application, storageInB); assertNotNull(storageInB); assertEquals("128 B", storageInBFormatted); long storageInKb = 1024L; final String storageInKbFormatted = formatStorageSize(application, storageInKb); assertNotNull(storageInKb); assertEquals("1.0 kB", storageInKbFormatted); long storageInMb = storageInKb * 1024; final String storageInMbFormatted = formatStorageSize(application, storageInMb); assertNotNull(storageInMb); assertEquals("1.0 MB", storageInMbFormatted); long storageInGb = storageInMb * 1024; final String storageInGbFormatted = formatStorageSize(application, storageInGb); assertNotNull(storageInGb); assertEquals("1.0 GB", storageInGbFormatted); }