### Question:
XBeePacket { public int getPacketLength() { byte[] packetData = getPacketData(); if (packetData == null) return 0; return packetData.length; } protected  XBeePacket(); byte[] generateByteArray(); byte[] generateByteArrayEscaped(); abstract byte[] getPacketData(); int getPacketLength(); int getChecksum(); LinkedHashMap<String, String> getParameters(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); String toPrettyString(); static XBeePacket parsePacket(String packet, OperatingMode mode); static XBeePacket parsePacket(byte[] packet, OperatingMode mode);  }### Answer:
@Test public final void testGetPacketLengthNullData() { TestXBeePacket packet = new TestXBeePacket(); int expectedLength = 0; int length = packet.getPacketLength(); assertThat("The length of the packet is not the expected one", length, is(equalTo(expectedLength))); }
@Test public final void testGetPacketLengthEmptyData() { TestXBeePacket packet = new TestXBeePacket() { public byte[] getPacketData() { return new byte[0]; } }; int expectedLength = 0; int length = packet.getPacketLength(); assertThat("The length of the packet is not the expected one", length, is(equalTo(expectedLength))); }
@Test public final void testGetPacketLength() { final byte[] dataArray = new byte[]{0x17, 0x01, 0x00, 0x13, (byte)0xA2, 0x00, 0x40, (byte)0xAD, 0x14, 0x2E, (byte)0xFF, (byte)0xFE, 0x02, 0x4E, 0x49}; TestXBeePacket packet = new TestXBeePacket() { public byte[] getPacketData() { return dataArray; } }; int expectedLength = dataArray.length; int length = packet.getPacketLength(); assertThat("The length of the packet is not the expected one", length, is(equalTo(expectedLength))); }