@Test public void GIVEN_uv_index_between_2_point_6_and_5_point_5_degrees_celsius_WHEN_color_requested_THEN_returns_value_to_one_digit_and_moderate_text() { testee = new UvIndexFormatter(new BigDecimal("2.6")); assertEquals("2.6 moderate", testee.format()); testee = new UvIndexFormatter(new BigDecimal("5.5")); assertEquals("5.5 moderate", testee.format()); }
public String format() { String formatted = "-.- -----"; if (uvIndex != null) { int uvIndexRounded = uvIndex.setScale(0, RoundingMode.HALF_DOWN).intValue(); String description = null; if (uvIndexRounded < 3) { description = "low"; } else if (uvIndexRounded > 10) { description = "extreme"; } else { switch (uvIndexRounded) { case 3: case 4: case 5: description = "moderate"; break; case 6: case 7: description = "high"; break; case 8: case 9: case 10: description = "very high"; break; } } formatted = String.format(Locale.US, "%1.1f %2s", uvIndex.setScale(1, RoundingMode.HALF_DOWN), description); } return formatted; }
UvIndexFormatter { public String format() { String formatted = "-.- -----"; if (uvIndex != null) { int uvIndexRounded = uvIndex.setScale(0, RoundingMode.HALF_DOWN).intValue(); String description = null; if (uvIndexRounded < 3) { description = "low"; } else if (uvIndexRounded > 10) { description = "extreme"; } else { switch (uvIndexRounded) { case 3: case 4: case 5: description = "moderate"; break; case 6: case 7: description = "high"; break; case 8: case 9: case 10: description = "very high"; break; } } formatted = String.format(Locale.US, "%1.1f %2s", uvIndex.setScale(1, RoundingMode.HALF_DOWN), description); } return formatted; } }
UvIndexFormatter { public String format() { String formatted = "-.- -----"; if (uvIndex != null) { int uvIndexRounded = uvIndex.setScale(0, RoundingMode.HALF_DOWN).intValue(); String description = null; if (uvIndexRounded < 3) { description = "low"; } else if (uvIndexRounded > 10) { description = "extreme"; } else { switch (uvIndexRounded) { case 3: case 4: case 5: description = "moderate"; break; case 6: case 7: description = "high"; break; case 8: case 9: case 10: description = "very high"; break; } } formatted = String.format(Locale.US, "%1.1f %2s", uvIndex.setScale(1, RoundingMode.HALF_DOWN), description); } return formatted; } UvIndexFormatter(BigDecimal uvIndex); }
UvIndexFormatter { public String format() { String formatted = "-.- -----"; if (uvIndex != null) { int uvIndexRounded = uvIndex.setScale(0, RoundingMode.HALF_DOWN).intValue(); String description = null; if (uvIndexRounded < 3) { description = "low"; } else if (uvIndexRounded > 10) { description = "extreme"; } else { switch (uvIndexRounded) { case 3: case 4: case 5: description = "moderate"; break; case 6: case 7: description = "high"; break; case 8: case 9: case 10: description = "very high"; break; } } formatted = String.format(Locale.US, "%1.1f %2s", uvIndex.setScale(1, RoundingMode.HALF_DOWN), description); } return formatted; } UvIndexFormatter(BigDecimal uvIndex); String format(); }
UvIndexFormatter { public String format() { String formatted = "-.- -----"; if (uvIndex != null) { int uvIndexRounded = uvIndex.setScale(0, RoundingMode.HALF_DOWN).intValue(); String description = null; if (uvIndexRounded < 3) { description = "low"; } else if (uvIndexRounded > 10) { description = "extreme"; } else { switch (uvIndexRounded) { case 3: case 4: case 5: description = "moderate"; break; case 6: case 7: description = "high"; break; case 8: case 9: case 10: description = "very high"; break; } } formatted = String.format(Locale.US, "%1.1f %2s", uvIndex.setScale(1, RoundingMode.HALF_DOWN), description); } return formatted; } UvIndexFormatter(BigDecimal uvIndex); String format();  }