@Test public void GIVEN_null_pressure_WHEN_millibars_formatting_requested_THEN_returns_blank_millibars_value() { testee = new PressureFormatter(null); assertEquals("----.- mb", testee.format(PressureUnit.MILLIBARS)); }
public String format(PressureUnit unit) { String formatted; if (pressure != null) { String formatString; int scale; if (unit == HECTOPASCALS) { formatString = "%1.1f hPa"; scale = 1; } else if (unit == MILLIBARS) { formatString = "%1.1f mb"; scale = 1; } else if (unit == KILIOPASCALS) { formatString = "%1.2f kPa"; scale = 2; } else if (unit == INCHES_OF_MERCURY) { formatString = "%1.2f inHg"; scale = 2; } else { formatString = "%1.1f mmHg"; scale = 1; } formatted = String.format(Locale.US, formatString, pressure.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == HECTOPASCALS) { formatted = "----.- hPa"; } else if (unit == MILLIBARS) { formatted = "----.- mb"; } else if (unit == KILIOPASCALS) { formatted = "---.-- kPa"; } else if (unit == INCHES_OF_MERCURY) { formatted = "--.-- inHg"; } else { formatted = "---.- mmHg"; } } return formatted; }
PressureFormatter { public String format(PressureUnit unit) { String formatted; if (pressure != null) { String formatString; int scale; if (unit == HECTOPASCALS) { formatString = "%1.1f hPa"; scale = 1; } else if (unit == MILLIBARS) { formatString = "%1.1f mb"; scale = 1; } else if (unit == KILIOPASCALS) { formatString = "%1.2f kPa"; scale = 2; } else if (unit == INCHES_OF_MERCURY) { formatString = "%1.2f inHg"; scale = 2; } else { formatString = "%1.1f mmHg"; scale = 1; } formatted = String.format(Locale.US, formatString, pressure.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == HECTOPASCALS) { formatted = "----.- hPa"; } else if (unit == MILLIBARS) { formatted = "----.- mb"; } else if (unit == KILIOPASCALS) { formatted = "---.-- kPa"; } else if (unit == INCHES_OF_MERCURY) { formatted = "--.-- inHg"; } else { formatted = "---.- mmHg"; } } return formatted; } }
PressureFormatter { public String format(PressureUnit unit) { String formatted; if (pressure != null) { String formatString; int scale; if (unit == HECTOPASCALS) { formatString = "%1.1f hPa"; scale = 1; } else if (unit == MILLIBARS) { formatString = "%1.1f mb"; scale = 1; } else if (unit == KILIOPASCALS) { formatString = "%1.2f kPa"; scale = 2; } else if (unit == INCHES_OF_MERCURY) { formatString = "%1.2f inHg"; scale = 2; } else { formatString = "%1.1f mmHg"; scale = 1; } formatted = String.format(Locale.US, formatString, pressure.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == HECTOPASCALS) { formatted = "----.- hPa"; } else if (unit == MILLIBARS) { formatted = "----.- mb"; } else if (unit == KILIOPASCALS) { formatted = "---.-- kPa"; } else if (unit == INCHES_OF_MERCURY) { formatted = "--.-- inHg"; } else { formatted = "---.- mmHg"; } } return formatted; } PressureFormatter(Pressure pressure); }
PressureFormatter { public String format(PressureUnit unit) { String formatted; if (pressure != null) { String formatString; int scale; if (unit == HECTOPASCALS) { formatString = "%1.1f hPa"; scale = 1; } else if (unit == MILLIBARS) { formatString = "%1.1f mb"; scale = 1; } else if (unit == KILIOPASCALS) { formatString = "%1.2f kPa"; scale = 2; } else if (unit == INCHES_OF_MERCURY) { formatString = "%1.2f inHg"; scale = 2; } else { formatString = "%1.1f mmHg"; scale = 1; } formatted = String.format(Locale.US, formatString, pressure.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == HECTOPASCALS) { formatted = "----.- hPa"; } else if (unit == MILLIBARS) { formatted = "----.- mb"; } else if (unit == KILIOPASCALS) { formatted = "---.-- kPa"; } else if (unit == INCHES_OF_MERCURY) { formatted = "--.-- inHg"; } else { formatted = "---.- mmHg"; } } return formatted; } PressureFormatter(Pressure pressure); String format(PressureUnit unit); }
PressureFormatter { public String format(PressureUnit unit) { String formatted; if (pressure != null) { String formatString; int scale; if (unit == HECTOPASCALS) { formatString = "%1.1f hPa"; scale = 1; } else if (unit == MILLIBARS) { formatString = "%1.1f mb"; scale = 1; } else if (unit == KILIOPASCALS) { formatString = "%1.2f kPa"; scale = 2; } else if (unit == INCHES_OF_MERCURY) { formatString = "%1.2f inHg"; scale = 2; } else { formatString = "%1.1f mmHg"; scale = 1; } formatted = String.format(Locale.US, formatString, pressure.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN)); } else { if (unit == HECTOPASCALS) { formatted = "----.- hPa"; } else if (unit == MILLIBARS) { formatted = "----.- mb"; } else if (unit == KILIOPASCALS) { formatted = "---.-- kPa"; } else if (unit == INCHES_OF_MERCURY) { formatted = "--.-- inHg"; } else { formatted = "---.- mmHg"; } } return formatted; } PressureFormatter(Pressure pressure); String format(PressureUnit unit);  }