MySQLHandshakePacket implements MySQLPacket { @Override public void write(final MySQLPacketPayload payload) { payload.writeInt1(protocolVersion); payload.writeStringNul(serverVersion); payload.writeInt4(connectionId); payload.writeStringNul(new String(authPluginData.getAuthPluginDataPart1())); payload.writeInt2(capabilityFlagsLower); payload.writeInt1(characterSet); payload.writeInt2(statusFlag.getValue()); payload.writeInt2(capabilityFlagsUpper); payload.writeInt1(isClientPluginAuth() ? authPluginData.getAuthPluginData().length + 1 : 0); payload.writeReserved(10); writeAuthPluginDataPart2(payload); writeAuthPluginName(payload); } MySQLHandshakePacket(final int connectionId, final MySQLAuthPluginData authPluginData);  MySQLHandshakePacket(final MySQLPacketPayload payload); void setAuthPluginName(final MySQLAuthenticationMethod mysqlAuthenticationMethod); @Override void write(final MySQLPacketPayload payload); @Override int getSequenceId();  }
@Test public void assertWrite() { MySQLAuthPluginData authPluginData = new MySQLAuthPluginData(part1, part2); new MySQLHandshakePacket(1000, authPluginData).write(payload); verify(payload).writeInt1(MySQLServerInfo.PROTOCOL_VERSION); verify(payload).writeStringNul(MySQLServerInfo.getServerVersion()); verify(payload).writeInt4(1000); verify(payload).writeStringNul(new String(authPluginData.getAuthPluginDataPart1())); verify(payload).writeInt2(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower()); verify(payload).writeInt1(MySQLServerInfo.CHARSET); verify(payload).writeInt2(MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue()); verify(payload).writeInt2(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsUpper()); verify(payload).writeInt1(authPluginData.getAuthPluginData().length + 1); verify(payload).writeReserved(10); verify(payload).writeStringNul(new String(authPluginData.getAuthPluginDataPart2())); }