### Question:
BulkRedisReply extends CommonRedisReply { public void setLength(int length) { this.length = length; } BulkRedisReply(byte[] value);  BulkRedisReply(); void setLength(int length); @Override void doEncode(ByteBuf out);  }### Answer:
@Test public void encode() { ByteBuf buf = Unpooled.buffer(); IRedisReply redisReply = new BulkRedisReply(); ((BulkRedisReply) redisReply).setLength(6); ((BulkRedisReply) redisReply).setValue("foobar".getBytes()); redisReply.encode(buf); assertEquals(Type.BULK,redisReply.getType()); assertTrue(buf.isReadable()); assertEquals('$',(char)buf.readByte()); assertEquals('6',(char)buf.readByte()); assertEquals(RedisConstants.CR_BYTE,buf.readByte()); assertEquals(RedisConstants.LF_BYTE,buf.readByte()); assertEquals("foobar",readToStr(buf,6)); assertEquals(RedisConstants.CR_BYTE,buf.readByte()); assertEquals(RedisConstants.LF_BYTE,buf.readByte()); assertFalse(buf.isReadable()); }
@Test public void encodeNull(){ ByteBuf buf = Unpooled.buffer(); IRedisReply redisReply = new BulkRedisReply(); ((BulkRedisReply) redisReply).setLength(-1); redisReply.encode(buf); assertEquals(Type.BULK,redisReply.getType()); assertTrue(buf.isReadable()); assertEquals('$',(char)buf.readByte()); assertEquals('-',(char)buf.readByte()); assertEquals('1',(char)buf.readByte()); assertEquals(RedisConstants.CR_BYTE,buf.readByte()); assertEquals(RedisConstants.LF_BYTE,buf.readByte()); assertFalse(buf.isReadable()); }