### Question:
Utils { static ByteBuf encodeRemainingLength(int value) throws CorruptedFrameException { if (value > MAX_LENGTH_LIMIT || value < 0) { throw new CorruptedFrameException("Value should in range 0.." + MAX_LENGTH_LIMIT + " found " + value); } ByteBuf encoded = Unpooled.buffer(4); byte digit; do { digit = (byte) (value % 128); value = value / 128; if (value > 0) { digit = (byte) (digit | 0x80); } encoded.writeByte(digit); } while (value > 0); return encoded; }   static final int MAX_LENGTH_LIMIT; }### Answer:
@Test(expected=CorruptedFrameException.class) public void testEncodeRemainingLength_invalid_upper() { Utils.encodeRemainingLength(Utils.MAX_LENGTH_LIMIT + 1); }
@Test(expected=CorruptedFrameException.class) public void testEncodeRemainingLength_invalid_lower() { Utils.encodeRemainingLength(-1); }
@Test public void testEncodeRemainingLenght() { verifyBuff(1, new byte[]{0}, Utils.encodeRemainingLength(0)); verifyBuff(1, new byte[]{0x7F}, Utils.encodeRemainingLength(127)); verifyBuff(2, new byte[]{(byte)0x80, 0x01}, Utils.encodeRemainingLength(128)); verifyBuff(2, new byte[]{(byte)0xFF, 0x7F}, Utils.encodeRemainingLength(16383)); verifyBuff(3, new byte[]{(byte)0x80, (byte)0x80, 0x01}, Utils.encodeRemainingLength(16384)); verifyBuff(3, new byte[]{(byte)0xFF, (byte)0xFF, 0x7F}, Utils.encodeRemainingLength(2097151)); verifyBuff(4, new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, 0x01}, Utils.encodeRemainingLength(2097152)); verifyBuff(4, new byte[]{(byte)0xFF, (byte)0xFF, (byte)0xFF, 0x7F}, Utils.encodeRemainingLength(268435455)); }