NumberUtils { public static int requireUnsignedShort(int i) { if (i > UNSIGNED_SHORT_MAX_VALUE) { throw new IllegalArgumentException( String.format("%d is larger than %d bits", i, UNSIGNED_SHORT_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("requireUnsignedShort returns length if 65_535") @Test void requireUnsignedShort() { assertThat(NumberUtils.requireUnsignedShort((1 << 16) - 1)).isEqualTo(65_535); }
@DisplayName("requireUnsignedShort throws IllegalArgumentException if larger than 65_535") @Test void requireUnsignedShortOverFlow() { assertThatIllegalArgumentException() .isThrownBy(() -> NumberUtils.requireUnsignedShort(1 << 16)) .withMessage("%d is larger than 16 bits", 1 << 16); }