### Question:
HandshakeChallengePacketParser extends PacketParser { @Override public byte[] serialize() throws PacketParserException { byte[] outputArray = null; try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bos)) { out.writeByte(PACKETS.HANDSHAKE_CHALLENGE.ordinal()); if (owner.getChallenge().length > 0x0000ffff) throw new PacketParserException("Invalid Handshake Challenge has unsupported challenge size."); out.write((byte) ((owner.getChallenge().length & 0xff00) >> 8)); out.write((byte) (owner.getChallenge().length & 0x00ff)); out.write(owner.getChallenge()); outputArray = bos.toByteArray(); } catch (IOException ignored) { } return outputArray; } HandshakeChallengePacketParser(HandshakeChallengePacket handshakeChallengePacket); @Override Packet parse(PacketBuffer packetBuffer); @Override byte[] serialize();  }### Answer:
@Test public void serialize() throws Exception, PacketParserException { HandshakeChallengePacket handshakeChallengePacket = new HandshakeChallengePacket(); byte[] bytes = handshakeChallengePacket.getParser().serialize(); assertEquals(PACKETS.HANDSHAKE_CHALLENGE.ordinal(), bytes[0]); short size = (short) ((0xff & bytes[1]) << 8 | (0xff & bytes[2])); byte[] challengeAfter = new byte[size]; System.arraycopy(bytes, 3, challengeAfter, 0, size); assertArrayEquals(handshakeChallengePacket.getChallenge(), challengeAfter); }