@Test public void GIVEN_null_rainfall_WHEN_millmetres_formatting_requested_THEN_returns_blank_millmetres_value() { testee = new RainfallFormatter(null); assertEquals("-.-- mm", testee.format(RainfallUnit.MILLIMETRES)); }
public String format(RainfallUnit unit) { String formatted; if (rainfall != null) { String formatString; if (unit == MILLIMETRES) { formatString = "%1.2f mm"; } else { formatString = "%1.2f in"; } formatted = String.format(Locale.US, formatString, rainfall.getValue(unit).setScale(2, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm"; } else { formatted = "-.-- in"; } } return formatted; }
RainfallFormatter { public String format(RainfallUnit unit) { String formatted; if (rainfall != null) { String formatString; if (unit == MILLIMETRES) { formatString = "%1.2f mm"; } else { formatString = "%1.2f in"; } formatted = String.format(Locale.US, formatString, rainfall.getValue(unit).setScale(2, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm"; } else { formatted = "-.-- in"; } } return formatted; } }
RainfallFormatter { public String format(RainfallUnit unit) { String formatted; if (rainfall != null) { String formatString; if (unit == MILLIMETRES) { formatString = "%1.2f mm"; } else { formatString = "%1.2f in"; } formatted = String.format(Locale.US, formatString, rainfall.getValue(unit).setScale(2, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm"; } else { formatted = "-.-- in"; } } return formatted; } RainfallFormatter(Rainfall rainfall); }
RainfallFormatter { public String format(RainfallUnit unit) { String formatted; if (rainfall != null) { String formatString; if (unit == MILLIMETRES) { formatString = "%1.2f mm"; } else { formatString = "%1.2f in"; } formatted = String.format(Locale.US, formatString, rainfall.getValue(unit).setScale(2, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm"; } else { formatted = "-.-- in"; } } return formatted; } RainfallFormatter(Rainfall rainfall); String format(RainfallUnit unit); }
RainfallFormatter { public String format(RainfallUnit unit) { String formatted; if (rainfall != null) { String formatString; if (unit == MILLIMETRES) { formatString = "%1.2f mm"; } else { formatString = "%1.2f in"; } formatted = String.format(Locale.US, formatString, rainfall.getValue(unit).setScale(2, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm"; } else { formatted = "-.-- in"; } } return formatted; } RainfallFormatter(Rainfall rainfall); String format(RainfallUnit unit);  }