### Question:
RegisterSlaveCommandPacket extends AbstractCommandPacket { @Override public ByteBuf toByteBuf() { ByteBuf result = ByteBufAllocator.DEFAULT.heapBuffer(); DataTypesCodec.writeByte(getCommand(), result); DataTypesCodec.writeInt4LE(serverId, result); DataTypesCodec.writeByte((byte) reportHost.getBytes().length, result); DataTypesCodec.writeBytes(reportHost.getBytes(), result); DataTypesCodec.writeByte((byte) reportUser.getBytes().length, result); DataTypesCodec.writeBytes(reportUser.getBytes(), result); DataTypesCodec.writeByte((byte) reportPassword.getBytes().length, result); DataTypesCodec.writeBytes(reportPassword.getBytes(), result); DataTypesCodec.writeInt2LE(reportPort, result); DataTypesCodec.writeInt4LE(0, result); DataTypesCodec.writeInt4LE(0, result); return result; } RegisterSlaveCommandPacket(); @Override ByteBuf toByteBuf();  }### Answer:
@Test public void assertToByteBuf() { RegisterSlaveCommandPacket registerSlaveCommandPacket = new RegisterSlaveCommandPacket(); registerSlaveCommandPacket.setReportHost("localhost"); registerSlaveCommandPacket.setReportPort((short) 3306); registerSlaveCommandPacket.setReportUser("root"); registerSlaveCommandPacket.setReportPassword(""); registerSlaveCommandPacket.setServerId(1); assertThat(registerSlaveCommandPacket.toByteBuf(), is(getExpectedByteBuf())); }