NumberUtils { public static int requireUnsignedMedium(int i) { if (i > UNSIGNED_MEDIUM_MAX_VALUE) { throw new IllegalArgumentException( String.format("%d is larger than %d bits", i, UNSIGNED_MEDIUM_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("requireUnsignedMedium returns length if 16_777_215") @Test void requireUnsignedMedium() { assertThat(NumberUtils.requireUnsignedMedium((1 << 24) - 1)).isEqualTo(16_777_215); }
@DisplayName("requireUnsignedMedium throws IllegalArgumentException if larger than 16_777_215") @Test void requireUnsignedMediumOverFlow() { assertThatIllegalArgumentException() .isThrownBy(() -> NumberUtils.requireUnsignedMedium(1 << 24)) .withMessage("%d is larger than 24 bits", 1 << 24); }