### Question:
AppSizeUtil { static String formatSize(long size) { if (size / (1024 * 1024 * 1024) > 0) { float tmpSize = (float) (size) / (float) (1024 * 1024 * 1024); DecimalFormat df = new DecimalFormat("#.##"); return df.format(tmpSize) + "GB"; } else if (size / (1024 * 1024) > 0) { float tmpSize = (float) (size) / (float) (1024 * 1024); DecimalFormat df = new DecimalFormat("#.##"); return df.format(tmpSize) + "MB"; } else if (size / 1024 > 0) { return (size / (1024)) + "KB"; } else { return size + "B"; } }    }### Answer:
@Test public void formatSize() { final long oneByte = 1; final long oneKByte = 1 * 1024; final long oneMByte = 1 * 1024 * 1024; final long oneGByte = 1 * 1024 * 1024 * 1024; Assert.assertEquals("2B", AppSizeUtil.formatSize(oneByte * 2)); Assert.assertEquals("2KB", AppSizeUtil.formatSize(oneKByte * 2 + oneByte)); Assert.assertEquals("2MB", AppSizeUtil.formatSize(oneMByte * 2 + 2 * oneKByte)); Assert.assertEquals("2.1MB", AppSizeUtil.formatSize(oneMByte * 2 + 101 * oneKByte)); Assert.assertEquals("2.1GB", AppSizeUtil.formatSize(oneGByte * 2 + 101 * oneMByte + 101 * oneKByte)); Assert.assertEquals("2GB", AppSizeUtil.formatSize(oneGByte * 2 + 101 * oneKByte)); }