@Test public void GIVEN_null_rainfall_rate_WHEN_inches_formatting_requested_THEN_returns_blank_inches_value() { testee = new RainfallRateFormatter(null); assertEquals("-.--- in/min", testee.format(RainfallUnit.INCHES)); }
public String format(RainfallUnit unit) { String formatted; if (rainfallRatePerMinute != null) { String formatString; int scale; if (unit == MILLIMETRES) { formatString = "%1.2f mm/min"; scale = 2; } else { formatString = "%1.3f in/min"; scale = 3; } formatted = String.format(Locale.US, formatString, rainfallRatePerMinute.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm/min"; } else { formatted = "-.--- in/min"; } } return formatted; }
RainfallRateFormatter { public String format(RainfallUnit unit) { String formatted; if (rainfallRatePerMinute != null) { String formatString; int scale; if (unit == MILLIMETRES) { formatString = "%1.2f mm/min"; scale = 2; } else { formatString = "%1.3f in/min"; scale = 3; } formatted = String.format(Locale.US, formatString, rainfallRatePerMinute.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm/min"; } else { formatted = "-.--- in/min"; } } return formatted; } }
RainfallRateFormatter { public String format(RainfallUnit unit) { String formatted; if (rainfallRatePerMinute != null) { String formatString; int scale; if (unit == MILLIMETRES) { formatString = "%1.2f mm/min"; scale = 2; } else { formatString = "%1.3f in/min"; scale = 3; } formatted = String.format(Locale.US, formatString, rainfallRatePerMinute.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm/min"; } else { formatted = "-.--- in/min"; } } return formatted; } RainfallRateFormatter(Rainfall rainfallRatePerMinute); }
RainfallRateFormatter { public String format(RainfallUnit unit) { String formatted; if (rainfallRatePerMinute != null) { String formatString; int scale; if (unit == MILLIMETRES) { formatString = "%1.2f mm/min"; scale = 2; } else { formatString = "%1.3f in/min"; scale = 3; } formatted = String.format(Locale.US, formatString, rainfallRatePerMinute.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm/min"; } else { formatted = "-.--- in/min"; } } return formatted; } RainfallRateFormatter(Rainfall rainfallRatePerMinute); String format(RainfallUnit unit); }
RainfallRateFormatter { public String format(RainfallUnit unit) { String formatted; if (rainfallRatePerMinute != null) { String formatString; int scale; if (unit == MILLIMETRES) { formatString = "%1.2f mm/min"; scale = 2; } else { formatString = "%1.3f in/min"; scale = 3; } formatted = String.format(Locale.US, formatString, rainfallRatePerMinute.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm/min"; } else { formatted = "-.--- in/min"; } } return formatted; } RainfallRateFormatter(Rainfall rainfallRatePerMinute); String format(RainfallUnit unit);  }