@Test public void GIVEN_non_null_rainfall_rate_WHEN_millmetres_formatting_requested_THEN_returns_millmetres_value_to_three_digits() { testee = new RainfallRateFormatter(new Rainfall(new BigDecimal("5.666"))); assertEquals("5.67 mm/min", testee.format(RainfallUnit.MILLIMETRES)); testee = new RainfallRateFormatter(new Rainfall(new BigDecimal("0"))); assertEquals("0.00 mm/min", testee.format(RainfallUnit.MILLIMETRES)); testee = new RainfallRateFormatter(new Rainfall(new BigDecimal("0.001"))); assertEquals("0.00 mm/min", testee.format(RainfallUnit.MILLIMETRES)); testee = new RainfallRateFormatter(new Rainfall(new BigDecimal("5.655"))); assertEquals("5.65 mm/min", testee.format(RainfallUnit.MILLIMETRES)); }
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);  }