### Question:
PacketFactory { public static Packet toPacket(byte[] octets) { int packetLen = octets[3] & 0xFF; packetLen |= ((octets[2] << 8) & 0xFF00); return toPacket(ByteBuffer.wrap(octets, 0, packetLen)); } private  PacketFactory(); static Packet toPacket(byte[] octets); static Packet toPacket(ByteBuffer data); static Attribute nextAttribute(ByteBuffer bfr);  }### Answer:
@Test public void testRfc2865Sec7dot1Example() throws UnknownHostException { final String hex = "01 00 00 38 0f 40 3f 94 73 97 80 57 bd 83 d5 cb" + "98 f4 22 7a 01 06 6e 65 6d 6f 02 12 0d be 70 8d" + "93 d4 13 ce 31 96 e4 3f 78 2a 0a ee 04 06 c0 a8" + "01 10 05 06 00 00 00 03"; final ByteBuffer bfr = Utils.toBuffer(hex); dumpBfr(bfr); final Packet pkt = PacketFactory.toPacket(bfr); Assert.assertNotNull(pkt.getAuthenticator(), "authenticator should be defined"); Assert.assertEquals(pkt.getType(), PacketType.ACCESS_REQUEST, "Incorrect type code"); Assert.assertEquals(pkt.getIdentifier(), 0, "packet identifier should have been 0"); Assert.assertEquals(pkt.getAttributeSet().size(), 4, "packet attributes contained"); Assert.assertEquals(pkt.getAttributeAt(0).getClass().getSimpleName(), UserNameAttribute.class.getSimpleName(), "0 attribute"); Assert.assertEquals(((UserNameAttribute) pkt.getAttributeAt(0)).getName(), "nemo", "user name"); Assert.assertEquals(pkt.getAttributeAt(1).getClass().getSimpleName(), UserPasswordAttribute.class.getSimpleName(), "1 attribute"); Assert.assertEquals(pkt.getAttributeAt(2).getClass().getSimpleName(), NASIPAddressAttribute.class.getSimpleName(), "2 attribute"); Assert.assertEquals(((NASIPAddressAttribute) pkt.getAttributeAt(2)).getIpAddress(), InetAddress.getByAddress(new byte[] { (byte) 192, (byte) 168, 1, 16 }), "NAS IP address"); Assert.assertEquals(pkt.getAttributeAt(3).getClass().getSimpleName(), NASPortAttribute.class.getSimpleName(), "3 attribute"); Assert.assertEquals(((NASPortAttribute) pkt.getAttributeAt(3)).getPort(), 3, "NAS port"); }