Heating extends BaseOpenMessage { public static Heating requestTemperature(String where, TemperatureScale scale) { checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE_TEMPERATURE, checkIsInteger(where)); checkNotNull(scale, "invalid null scale"); return new Heating(format(FORMAT_DIMENSION, WHO, where, READ_TEMPERATURE), scale); } private  Heating(String value, TemperatureScale scale); static Heating requestTemperature(String where, TemperatureScale scale); static Heating requestTemperature(String where); static Func1<OpenSession, OpenSession> handleTemperature(Action1<Double> onSuccess, Action0 onError);  }
@Test public void testRequestTemperature() { assertEquals("should be a valid value", "*#4*0*0##", requestTemperature("0").getValue()); assertEquals("should be a valid value", "*#4*001*0##", requestTemperature("001").getValue()); assertEquals("should be a valid value", "*#4*899*0##", requestTemperature("899").getValue()); }
@Test public void testRequestTemperatureWithScale() { assertEquals("should be a valid value", "*#4*0*0##", requestTemperature("0", CELSIUS).getValue()); assertEquals("should be a valid value", "*#4*001*0##", requestTemperature("001", FAHRENHEIT).getValue()); assertEquals("should be a valid value", "*#4*899*0##", requestTemperature("899", KELVIN).getValue()); }
@Test public void testRequestTemperatureInvalid() { assertThat(captureThrowable(() -> requestTemperature(null))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> requestTemperature(""))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> requestTemperature("XXX"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> requestTemperature("-1"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("value must be between 0 and 899"); assertThat(captureThrowable(() -> requestTemperature("900"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("value must be between 0 and 899"); assertThat(captureThrowable(() -> requestTemperature("1", null))) .isInstanceOf(NullPointerException.class) .hasMessage("invalid null scale"); }