### Question:
Packet { public byte[] getOctets() { final ByteArrayOutputStream s = new ByteArrayOutputStream(); byte[] bytes = null; s.write(type.getTypeCode()); s.write(id); try { s.write(new byte[] { 0, 0 }); } catch (final IOException e) { } bytes = authenticator.getOctets(); try { s.write(bytes); } catch (final IOException e) { } for (int i = 0; i < attrs.size(); i++) { final Attribute a = attrs.getAttributeAt(i); bytes = a.getOctets(); try { s.write(bytes); } catch (final IOException e) { } } final byte[] res = s.toByteArray(); res[2] = ((byte) ((res.length >> 8) & 0xFF)); res[3] = ((byte) (res.length & 0xFF)); return res; } Packet(PacketType packetType);  Packet(PacketType packetType, short id, Authenticator auth); PacketType getType(); short getIdentifier(); void setIdentifier(short id); Authenticator getAuthenticator(); void addAttribute(Attribute attr); AttributeSet getAttributeSet(); Attribute getAttributeAt(int pos); @Override String toString(); void setAuthenticator(Authenticator authenticator); byte[] getOctets();  }### Answer:
@Test public void testSerializingOfReject() throws IOException { final String res = "03 03 00 1b a4 2f 4f ca 45 91 6c 4e 09 c8 34 0f 9e 74 6a a0 12 07 68 65 6c 6c 6f"; final byte[] bytes = Utils.toByteArray(res); final Packet p = PacketFactory.toPacket(bytes); final byte[] data = p.getOctets(); final String hex = Utils.toSpacedHex(ByteBuffer.wrap(data)); Assert.assertEquals(hex, res, "serialized form should match original"); }