### Question:
ReceivePacket extends XBeeAPIPacket { public static ReceivePacket createPacket(byte[] payload) { if (payload == null) throw new NullPointerException("Receive packet payload cannot be null."); if (payload.length < MIN_API_PAYLOAD_LENGTH) throw new IllegalArgumentException("Incomplete Receive packet."); if ((payload[0] & 0xFF) != APIFrameType.RECEIVE_PACKET.getValue()) throw new IllegalArgumentException("Payload is not a Receive packet."); int index = 1; XBee64BitAddress sourceAddress64 = new XBee64BitAddress(Arrays.copyOfRange(payload, index, index + 8)); index = index + 8; XBee16BitAddress sourceAddress16 = new XBee16BitAddress(payload[index] & 0xFF, payload[index + 1] & 0xFF); index = index + 2; int receiveOptions = payload[index] & 0xFF; index = index + 1; byte[] data = null; if (index < payload.length) data = Arrays.copyOfRange(payload, index, payload.length); return new ReceivePacket(sourceAddress64, sourceAddress16, receiveOptions, data); } ReceivePacket(XBee64BitAddress sourceAddress64, XBee16BitAddress sourceAddress16, int receiveOptions, byte[] rfData); static ReceivePacket createPacket(byte[] payload); @Override boolean needsAPIFrameID(); @Override boolean isBroadcast(); XBee64BitAddress get64bitSourceAddress(); XBee16BitAddress get16bitSourceAddress(); int getReceiveOptions(); void setRFData(byte[] rfData); byte[] getRFData(); @Override LinkedHashMap<String, String> getAPIPacketParameters();  }### Answer:
@Test public final void testCreatePacketNullPayload() { byte[] payload = null; exception.expect(NullPointerException.class); exception.expectMessage(is(equalTo("Receive packet payload cannot be null."))); ReceivePacket.createPacket(payload); }
@Test public final void testCreatePacketEmptyPayload() { byte[] payload = new byte[0]; exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Incomplete Receive packet."))); ReceivePacket.createPacket(payload); }
@Test public final void testCreatePacketPayloadShorterThanNeeded() { int frameType = APIFrameType.RECEIVE_PACKET.getValue(); XBee64BitAddress source64Addr = new XBee64BitAddress("0013A2004032D9AB"); XBee16BitAddress source16Addr = new XBee16BitAddress("D817"); byte[] payload = new byte[11]; payload[0] = (byte)frameType; System.arraycopy(source64Addr.getValue(), 0, payload, 1, source64Addr.getValue().length); System.arraycopy(source64Addr.getValue(), 0, payload, 9, source16Addr.getValue().length); exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Incomplete Receive packet."))); ReceivePacket.createPacket(payload); }
@Test public final void testCreatePacketPayloadNotIncludingFrameType() { XBee64BitAddress source64Addr = new XBee64BitAddress("0013A2004032D9AB"); XBee16BitAddress source16Addr = new XBee16BitAddress("D817"); int options = 40; byte[] data = new byte[]{0x68, 0x6F, 0x6C, 0x61}; byte[] payload = new byte[11 + data.length]; System.arraycopy(source64Addr.getValue(), 0, payload, 0, source64Addr.getValue().length); System.arraycopy(source16Addr.getValue(), 0, payload, 8, source16Addr.getValue().length); payload[10] = (byte)options; System.arraycopy(data, 0, payload, 11, data.length); exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Payload is not a Receive packet."))); ReceivePacket.createPacket(payload); }