DataSize implements Comparable<DataSize> { @JsonValue @Override public String toString() { if (floor(value) == value) { return (long) (floor(value)) + unit.getUnitString(); } return String.format(Locale.ENGLISH, "%.2f%s", value, unit.getUnitString()); } DataSize(double size, Unit unit); static DataSize succinctBytes(long bytes); static DataSize succinctDataSize(double size, Unit unit); long toBytes(); double getValue(); Unit getUnit(); double getValue(Unit unit); long roundTo(Unit unit); DataSize convertTo(Unit unit); DataSize convertToMostSuccinctDataSize(); @JsonValue @Override String toString(); @JsonCreator static DataSize valueOf(String size); @Override int compareTo(DataSize o); @Override boolean equals(Object o); @Override int hashCode();  }
@Test(dataProvider = "printedValues") public void testToString(String expectedString, double value, DataSize.Unit unit) { assertEquals(new DataSize(value, unit).toString(), expectedString); }
@Test(dataProvider = "printedValues") public void testNonEnglishLocale(String expectedString, double value, DataSize.Unit unit) { synchronized (Locale.class) { Locale previous = Locale.getDefault(); Locale.setDefault(Locale.GERMAN); try { assertEquals(new DataSize(value, unit).toString(), expectedString); } finally { Locale.setDefault(previous); } } }