### Question:
ClientAuthenticationPacket extends AbstractPacket { @Override @SneakyThrows public ByteBuf toByteBuf() { ByteBuf result = ByteBufAllocator.DEFAULT.heapBuffer(); DataTypesCodec.writeInt4LE(clientCapability, result); DataTypesCodec.writeInt4LE(1 << 24, result); DataTypesCodec.writeByte(charsetNumber, result); DataTypesCodec.writeBytes(new byte[23], result); DataTypesCodec.writeBytes(username.getBytes(), result); DataTypesCodec.writeByte((byte) 0x00, result); if (Strings.isNullOrEmpty(password)) { DataTypesCodec.writeByte((byte) 0x00, result); } else { byte[] encryptedPassword = MySQLPasswordEncryptor.encryptWithMySQL41(password.getBytes(), authPluginData); DataTypesCodec.writeLengthCodedBinary(encryptedPassword, result); } if (null != databaseName) { DataTypesCodec.writeNulTerminatedString(databaseName, result); } if (null != authPluginName) { DataTypesCodec.writeNulTerminatedString(authPluginName, result); } return result; }  void setDatabaseName(final String databaseName); void setAuthPluginName(final String authPluginName); @Override @SneakyThrows ByteBuf toByteBuf();  }### Answer:
@Test public void assertToByteBufWithoutPassword() { ClientAuthenticationPacket clientAuthenticationPacket = createClientAuthenticationPacket(); ByteBuf actual = clientAuthenticationPacket.toByteBuf(); assertThat(ByteBufUtil.hexDump(actual), is("0da6090000000001080000000000000000000000000000000000000000000000726f6f7400006d7973716c006d7973716c5f6e61746976655f70617373776f726400")); }
@Test public void assertToByteBufWithPassword() { ClientAuthenticationPacket clientAuthenticationPacket = createClientAuthenticationPacket(); clientAuthenticationPacket.setPassword("root"); ByteBuf actual = clientAuthenticationPacket.toByteBuf(); assertThat(ByteBufUtil.hexDump(actual), is("0da6090000000001080000000000000000000000000000000000000000000000726f6f740014bccb5cac49b1430878e1fe07dff923de69b477af6d7973716c006d7973716c5f6e61746976655f70617373776f726400")); }