NumberUtils { public static int requireUnsignedByte(int i) { if (i > UNSIGNED_BYTE_MAX_VALUE) { throw new IllegalArgumentException( String.format("%d is larger than %d bits", i, UNSIGNED_BYTE_SIZE)); } return i; } private  NumberUtils(); static int requireNonNegative(int i, String message); static long requirePositive(long l, String message); static int requirePositive(int i, String message); static int requireUnsignedByte(int i); static int requireUnsignedMedium(int i); static int requireUnsignedShort(int i); static void encodeUnsignedMedium(ByteBuf byteBuf, int i); static final int MEDIUM_BYTES; }
@DisplayName("requireUnsignedByte returns length if 255") @Test void requireUnsignedByte() { assertThat(NumberUtils.requireUnsignedByte((1 << 8) - 1)).isEqualTo(255); }
@DisplayName("requireUnsignedByte throws IllegalArgumentException if larger than 255") @Test void requireUnsignedByteOverFlow() { assertThatIllegalArgumentException() .isThrownBy(() -> NumberUtils.requireUnsignedByte(1 << 8)) .withMessage("%d is larger than 8 bits", 1 << 8); }