@Test public void testCheckRangeType_invalidGroup() { assertThat(captureThrowable(() -> checkRangeType("-1", Type.GROUP, NO_BUS))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("value must be between 1 and 255"); assertThat(captureThrowable(() -> checkRangeType("x", Type.GROUP, NO_BUS))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> checkRangeType("#", Type.GROUP, NO_BUS))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("invalid integer format"); assertThat(captureThrowable(() -> checkRangeType("0", Type.GROUP, NO_BUS))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("value must be between 1 and 255"); assertThat(captureThrowable(() -> checkRangeType("256", Type.GROUP, NO_BUS))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("value must be between 1 and 255"); }
protected static void checkRangeType(String where, Type type, String bus) { checkNotNull(where, "invalid null value: [where]"); checkNotNull(type, "invalid null value: [type]"); checkNotNull(bus, "invalid null value: [bus]"); checkArgument(where.length() >= 1 && where.length() <= 4, "invalid length [1-4]"); switch (type) { case GENERAL: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GENERAL_BUS: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkBus(bus); break; case AREA: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case AREA_BUS: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkBus(bus); break; case GROUP: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GROUP_BUS: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkBus(bus); break; case POINT_TO_POINT: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case POINT_TO_POINT_BUS: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkBus(bus); break; default: throw new IllegalArgumentException("invalid type"); } }
Lighting extends BaseOpenMessage { protected static void checkRangeType(String where, Type type, String bus) { checkNotNull(where, "invalid null value: [where]"); checkNotNull(type, "invalid null value: [type]"); checkNotNull(bus, "invalid null value: [bus]"); checkArgument(where.length() >= 1 && where.length() <= 4, "invalid length [1-4]"); switch (type) { case GENERAL: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GENERAL_BUS: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkBus(bus); break; case AREA: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case AREA_BUS: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkBus(bus); break; case GROUP: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GROUP_BUS: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkBus(bus); break; case POINT_TO_POINT: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case POINT_TO_POINT_BUS: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkBus(bus); break; default: throw new IllegalArgumentException("invalid type"); } } }
Lighting extends BaseOpenMessage { protected static void checkRangeType(String where, Type type, String bus) { checkNotNull(where, "invalid null value: [where]"); checkNotNull(type, "invalid null value: [type]"); checkNotNull(bus, "invalid null value: [bus]"); checkArgument(where.length() >= 1 && where.length() <= 4, "invalid length [1-4]"); switch (type) { case GENERAL: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GENERAL_BUS: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkBus(bus); break; case AREA: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case AREA_BUS: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkBus(bus); break; case GROUP: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GROUP_BUS: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkBus(bus); break; case POINT_TO_POINT: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case POINT_TO_POINT_BUS: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkBus(bus); break; default: throw new IllegalArgumentException("invalid type"); } } private  Lighting(String value); }
Lighting extends BaseOpenMessage { protected static void checkRangeType(String where, Type type, String bus) { checkNotNull(where, "invalid null value: [where]"); checkNotNull(type, "invalid null value: [type]"); checkNotNull(bus, "invalid null value: [bus]"); checkArgument(where.length() >= 1 && where.length() <= 4, "invalid length [1-4]"); switch (type) { case GENERAL: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GENERAL_BUS: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkBus(bus); break; case AREA: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case AREA_BUS: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkBus(bus); break; case GROUP: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GROUP_BUS: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkBus(bus); break; case POINT_TO_POINT: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case POINT_TO_POINT_BUS: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkBus(bus); break; default: throw new IllegalArgumentException("invalid type"); } } 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); }
Lighting extends BaseOpenMessage { protected static void checkRangeType(String where, Type type, String bus) { checkNotNull(where, "invalid null value: [where]"); checkNotNull(type, "invalid null value: [type]"); checkNotNull(bus, "invalid null value: [bus]"); checkArgument(where.length() >= 1 && where.length() <= 4, "invalid length [1-4]"); switch (type) { case GENERAL: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GENERAL_BUS: checkArgument(WHERE_GENERAL_VALUE.equals(where), "allowed value [0]"); checkBus(bus); break; case AREA: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkArgument(bus.isEmpty(), "invalid bus size"); break; case AREA_BUS: checkArgument( "00".equals(where) || (isInRange(WHERE_MIN_VALUE_AREA, WHERE_MAX_VALUE_AREA, checkIsInteger(where)) && where.length() == 1) || "100".equals(where), "allowed value [00, 1−9, 100]"); checkBus(bus); break; case GROUP: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case GROUP_BUS: checkRange(WHERE_MIN_VALUE_GROUP, WHERE_MAX_VALUE_GROUP, checkIsInteger(where)); checkBus(bus); break; case POINT_TO_POINT: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkArgument(bus.isEmpty(), "invalid bus size"); break; case POINT_TO_POINT_BUS: checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE, checkIsInteger(where)); checkBus(bus); break; default: throw new IllegalArgumentException("invalid type"); } } 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);  }