HeartbeatMessageSerializer extends ProtocolMessageSerializer<HeartbeatMessage> { @Override public byte[] serializeProtocolMessageContent() { LOGGER.debug("Serializing HeartbeatMessage"); writeHeartbeatMessageType(msg); writePayloadLength(msg); writePayload(msg); writePadding(msg); return getAlreadySerialized(); } HeartbeatMessageSerializer(HeartbeatMessage message, ProtocolVersion version); @Override byte[] serializeProtocolMessageContent();  }
@Test public void testSerializeProtocolMessageContent() { HeartbeatMessage msg = new HeartbeatMessage(); msg.setCompleteResultingMessage(expectedPart); msg.setHeartbeatMessageType(heartBeatType); msg.setPayloadLength(payloadLength); msg.setPayload(payload); msg.setPadding(padding); HeartbeatMessageSerializer serializer = new HeartbeatMessageSerializer(msg, ProtocolVersion.TLS12); assertArrayEquals(expectedPart, serializer.serialize()); }