Automation extends BaseOpenMessage { public static Automation requestStatus(String where) { checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); return new Automation(format(FORMAT_STATUS, WHO, where)); } private  Automation(String value); static Automation requestStop(String where); static Automation requestStop(String where, Type type, String bus); static Automation requestMoveUp(String where); static Automation requestMoveUp(String where, Type type, String bus); static Automation requestMoveDown(String where); static Automation requestMoveDown(String where, Type type, String bus); static Func1<OpenSession, OpenSession> handleResponse(Action0 onSuccess, Action0 onFail); static Automation requestStatus(String where); static Automation requestStatus(String where, Type type, String bus); static Func1<OpenSession, OpenSession> handleStatus(Action0 stopAction, Action0 upAction, Action0 downAction); static boolean isValidRangeType(String where, Type type, String bus);  }
@Test public void testRequestStatus() { assertEquals("should be a valid value", "*#2*21##", requestStatus("21").getValue()); assertEquals("should be a valid value", "*#2*0##", requestStatus("0").getValue()); assertEquals("should be a valid value", "*#2*9999##", requestStatus("9999").getValue()); assertEquals("should be a valid value", "*#2*01##", requestStatus("01").getValue()); assertEquals("should be a valid value", "*#2*1##", requestStatus("1").getValue()); assertEquals("should be a valid value", "*#2*09##", requestStatus("09").getValue()); assertEquals("should be a valid value", "*#2*9##", requestStatus("9").getValue()); }
@Test public void testRequestStatusWithType() { assertEquals("should be a valid value", "*#2*0##", requestStatus("0", Type.GENERAL, NO_BUS).getValue()); assertEquals("should be a valid value", "*#2*0#4#01##", requestStatus("0", Type.GENERAL_BUS, "01").getValue()); assertEquals("should be a valid value", "*#2*1##", requestStatus("1", Type.AREA, NO_BUS).getValue()); assertEquals("should be a valid value", "*#2*1#4#01##", requestStatus("1", Type.AREA_BUS, "01").getValue()); assertEquals("should be a valid value", "*#2*#1##", requestStatus("1", Type.GROUP, NO_BUS).getValue()); assertEquals("should be a valid value", "*#2*#1#4#01##", requestStatus("1", Type.GROUP_BUS, "01").getValue()); assertEquals("should be a valid value", "*#2*11##", requestStatus("11", Type.POINT_TO_POINT, NO_BUS).getValue()); assertEquals("should be a valid value", "*#2*11#4#01##", requestStatus("11", Type.POINT_TO_POINT_BUS, "01").getValue()); }
@Test public void testRequestStatusInvalid() { assertThat(captureThrowable(() -> requestStatus(null))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> requestStatus(""))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> requestStatus("AAA"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> requestStatus("-1"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("value must be between 0 and 9999"); assertThat(captureThrowable(() -> requestStatus("10000"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("value must be between 0 and 9999"); }