### Question:
BytesFormatter { public static String getStringDescriptionFor(long nBytes) { char[] units = { 'B', 'K', 'M', 'G', 'T', 'P' }; double current = nBytes; double prev = current; int index = 0; while ((current = current / 1024) >= 1) { prev = current; ++index; } assert index < units.length : "Too large a number."; return getFormatter().format(prev) + units[index]; } private  BytesFormatter(); static DecimalFormat getFormatter(); static String getStringDescriptionFor(long nBytes);  }### Answer:
@Test public void bytes() { assertThat(BytesFormatter.getStringDescriptionFor(100L), is("100.0B")); }
@Test public void kilobytes() { assertThat(BytesFormatter.getStringDescriptionFor(1024L), is("1.0K")); assertThat(BytesFormatter.getStringDescriptionFor(2256L), is("2.2K")); }
@Test public void megabytes() { assertThat(BytesFormatter.getStringDescriptionFor(1024L * 1024L), is("1.0M")); assertThat(BytesFormatter.getStringDescriptionFor((2024L * 1024L) + (256L * 1024L)), is("2.2M")); }
@Test public void gigabytes() { assertThat(BytesFormatter.getStringDescriptionFor(1024L * 1024L * 1024L), is("1.0G")); }
@Test public void terabytes() { assertThat(BytesFormatter.getStringDescriptionFor(1024L * 1024L * 1024L * 1024L), is("1.0T")); }
@Test public void petabytes() { assertThat(BytesFormatter.getStringDescriptionFor(1024L * 1024L * 1024L * 1024L * 1024L), is("1.0P")); }