Lighting extends BaseOpenMessage { public static Lighting requestTurnOn(String where) { checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); return new Lighting(format(FORMAT_REQUEST, WHO, ON, where)); } private  Lighting(String value); static Lighting requestTurnOn(String where); static Lighting requestTurnOn(String where, Type type, String bus); static Lighting requestTurnOff(String where); static Lighting requestTurnOff(String where, Type type, String bus); static Func1<OpenSession, OpenSession> handleResponse(Action0 onSuccess, Action0 onFail); static Lighting requestStatus(String where); static Lighting requestStatus(String where, Type type, String bus); static Func1<OpenSession, OpenSession> handleStatus(Action0 onStatus, Action0 offStatus); static boolean isValidRangeType(String where, Type type, String bus);  }
@Test public void testRequestTurnOn() { assertEquals("should be a valid value", "*1*1*21##", requestTurnOn("21").getValue()); assertEquals("should be a valid value", "*1*1*0##", requestTurnOn("0").getValue()); assertEquals("should be a valid value", "*1*1*9999##", requestTurnOn("9999").getValue()); assertEquals("should be a valid value", "*1*1*01##", requestTurnOn("01").getValue()); assertEquals("should be a valid value", "*1*1*1##", requestTurnOn("1").getValue()); assertEquals("should be a valid value", "*1*1*09##", requestTurnOn("09").getValue()); assertEquals("should be a valid value", "*1*1*9##", requestTurnOn("9").getValue()); }
@Test public void testRequestTurnOnWithType() { assertEquals("should be a valid value", "*1*1*0##", requestTurnOn("0", Type.GENERAL, NO_BUS).getValue()); assertEquals("should be a valid value", "*1*1*0#4#01##", requestTurnOn("0", Type.GENERAL_BUS, "01").getValue()); assertEquals("should be a valid value", "*1*1*9##", requestTurnOn("9", Type.AREA, NO_BUS).getValue()); assertEquals("should be a valid value", "*1*1*9#4#01##", requestTurnOn("9", Type.AREA_BUS, "01").getValue()); assertEquals("should be a valid value", "*1*1*#21##", requestTurnOn("21", Type.GROUP, NO_BUS).getValue()); assertEquals("should be a valid value", "*1*1*#21#4#01##", requestTurnOn("21", Type.GROUP_BUS, "01").getValue()); assertEquals("should be a valid value", "*1*1*21##", requestTurnOn("21", Type.POINT_TO_POINT, NO_BUS).getValue()); assertEquals("should be a valid value", "*1*1*21#4#01##", requestTurnOn("21", Type.POINT_TO_POINT_BUS, "01").getValue()); }
@Test public void testRequestTurnOnInvalid() { assertThat(captureThrowable(() -> requestTurnOn(null))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> requestTurnOn(""))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> requestTurnOn("a1"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> requestTurnOn("-1"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("value must be between 0 and 9999"); assertThat(captureThrowable(() -> requestTurnOn("10000"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("value must be between 0 and 9999"); }