@Test public void GIVEN_temperature_between_21_point_6_and_24_point_5_degrees_celsius_WHEN_color_requested_THEN_medium_orange_color_returned() { testee = new TemperatureColorizer(new Temperature(new BigDecimal("21.6"))); assertEquals(TemperatureColorizer.MEDIUM_ORANGE, testee.colorize()); testee = new TemperatureColorizer(new Temperature(new BigDecimal("24.5"))); assertEquals(TemperatureColorizer.MEDIUM_ORANGE, testee.colorize()); }
public int colorize() { int colorCode = WHITE; if (temperature != null) { BigDecimal temperatureCelsius = temperature.getValue(TemperatureUnit.CELSIUS); int temperatureCelsiusRounded = temperatureCelsius.setScale(0, RoundingMode.HALF_DOWN).intValue(); if (temperatureCelsiusRounded < 1) { colorCode = LIGHT_BLUE; } else if (temperatureCelsiusRounded > 24) { colorCode = DARK_ORANGE; } else { switch (temperatureCelsiusRounded) { case 1: case 2: case 3: colorCode = DARK_GREEN; break; case 4: case 5: case 6: colorCode = MEDIUM_GREEN; break; case 7: case 8: case 9: colorCode = LIGHT_GREEN; break; case 10: case 11: case 12: colorCode = LIGHT_YELLOW; break; case 13: case 14: case 15: colorCode = MEDIUM_YELLOW; break; case 16: case 17: case 18: colorCode = DARK_YELLOW; break; case 19: case 20: case 21: colorCode = LIGHT_ORANGE; break; case 22: case 23: case 24: colorCode = MEDIUM_ORANGE; break; } } } return colorCode; }
TemperatureColorizer { public int colorize() { int colorCode = WHITE; if (temperature != null) { BigDecimal temperatureCelsius = temperature.getValue(TemperatureUnit.CELSIUS); int temperatureCelsiusRounded = temperatureCelsius.setScale(0, RoundingMode.HALF_DOWN).intValue(); if (temperatureCelsiusRounded < 1) { colorCode = LIGHT_BLUE; } else if (temperatureCelsiusRounded > 24) { colorCode = DARK_ORANGE; } else { switch (temperatureCelsiusRounded) { case 1: case 2: case 3: colorCode = DARK_GREEN; break; case 4: case 5: case 6: colorCode = MEDIUM_GREEN; break; case 7: case 8: case 9: colorCode = LIGHT_GREEN; break; case 10: case 11: case 12: colorCode = LIGHT_YELLOW; break; case 13: case 14: case 15: colorCode = MEDIUM_YELLOW; break; case 16: case 17: case 18: colorCode = DARK_YELLOW; break; case 19: case 20: case 21: colorCode = LIGHT_ORANGE; break; case 22: case 23: case 24: colorCode = MEDIUM_ORANGE; break; } } } return colorCode; } }
TemperatureColorizer { public int colorize() { int colorCode = WHITE; if (temperature != null) { BigDecimal temperatureCelsius = temperature.getValue(TemperatureUnit.CELSIUS); int temperatureCelsiusRounded = temperatureCelsius.setScale(0, RoundingMode.HALF_DOWN).intValue(); if (temperatureCelsiusRounded < 1) { colorCode = LIGHT_BLUE; } else if (temperatureCelsiusRounded > 24) { colorCode = DARK_ORANGE; } else { switch (temperatureCelsiusRounded) { case 1: case 2: case 3: colorCode = DARK_GREEN; break; case 4: case 5: case 6: colorCode = MEDIUM_GREEN; break; case 7: case 8: case 9: colorCode = LIGHT_GREEN; break; case 10: case 11: case 12: colorCode = LIGHT_YELLOW; break; case 13: case 14: case 15: colorCode = MEDIUM_YELLOW; break; case 16: case 17: case 18: colorCode = DARK_YELLOW; break; case 19: case 20: case 21: colorCode = LIGHT_ORANGE; break; case 22: case 23: case 24: colorCode = MEDIUM_ORANGE; break; } } } return colorCode; } TemperatureColorizer(Temperature temperature); }
TemperatureColorizer { public int colorize() { int colorCode = WHITE; if (temperature != null) { BigDecimal temperatureCelsius = temperature.getValue(TemperatureUnit.CELSIUS); int temperatureCelsiusRounded = temperatureCelsius.setScale(0, RoundingMode.HALF_DOWN).intValue(); if (temperatureCelsiusRounded < 1) { colorCode = LIGHT_BLUE; } else if (temperatureCelsiusRounded > 24) { colorCode = DARK_ORANGE; } else { switch (temperatureCelsiusRounded) { case 1: case 2: case 3: colorCode = DARK_GREEN; break; case 4: case 5: case 6: colorCode = MEDIUM_GREEN; break; case 7: case 8: case 9: colorCode = LIGHT_GREEN; break; case 10: case 11: case 12: colorCode = LIGHT_YELLOW; break; case 13: case 14: case 15: colorCode = MEDIUM_YELLOW; break; case 16: case 17: case 18: colorCode = DARK_YELLOW; break; case 19: case 20: case 21: colorCode = LIGHT_ORANGE; break; case 22: case 23: case 24: colorCode = MEDIUM_ORANGE; break; } } } return colorCode; } TemperatureColorizer(Temperature temperature); int colorize(); }
TemperatureColorizer { public int colorize() { int colorCode = WHITE; if (temperature != null) { BigDecimal temperatureCelsius = temperature.getValue(TemperatureUnit.CELSIUS); int temperatureCelsiusRounded = temperatureCelsius.setScale(0, RoundingMode.HALF_DOWN).intValue(); if (temperatureCelsiusRounded < 1) { colorCode = LIGHT_BLUE; } else if (temperatureCelsiusRounded > 24) { colorCode = DARK_ORANGE; } else { switch (temperatureCelsiusRounded) { case 1: case 2: case 3: colorCode = DARK_GREEN; break; case 4: case 5: case 6: colorCode = MEDIUM_GREEN; break; case 7: case 8: case 9: colorCode = LIGHT_GREEN; break; case 10: case 11: case 12: colorCode = LIGHT_YELLOW; break; case 13: case 14: case 15: colorCode = MEDIUM_YELLOW; break; case 16: case 17: case 18: colorCode = DARK_YELLOW; break; case 19: case 20: case 21: colorCode = LIGHT_ORANGE; break; case 22: case 23: case 24: colorCode = MEDIUM_ORANGE; break; } } } return colorCode; } TemperatureColorizer(Temperature temperature); int colorize(); static final int WHITE; static final int LIGHT_BLUE; static final int DARK_GREEN; static final int MEDIUM_GREEN; static final int LIGHT_GREEN; static final int LIGHT_YELLOW; static final int MEDIUM_YELLOW; static final int DARK_YELLOW; static final int LIGHT_ORANGE; static final int MEDIUM_ORANGE; static final int DARK_ORANGE; }