### Question:
DeviceRequestPacket extends XBeeAPIPacket { public static DeviceRequestPacket createPacket(byte[] payload) { if (payload == null) throw new NullPointerException(ERROR_PAYLOAD_NULL); if (payload.length < MIN_API_PAYLOAD_LENGTH) throw new IllegalArgumentException(ERROR_INCOMPLETE_PACKET); if ((payload[0] & 0xFF) != APIFrameType.DEVICE_REQUEST.getValue()) throw new IllegalArgumentException(ERROR_NOT_VALID); int index = 1; int requestID = payload[index] & 0xFF; index = index + 1; index = index + 1; index = index + 1; int targetLength = payload[index] & 0xFF; index = index + 1; String target = null; if (targetLength > 0) { target = new String(Arrays.copyOfRange(payload, index, index + targetLength)); index = index + targetLength; } byte[] data = null; if (index < payload.length) data = Arrays.copyOfRange(payload, index, payload.length); return new DeviceRequestPacket(requestID, target, data); } DeviceRequestPacket(int requestID, String target, byte[] requestData); static DeviceRequestPacket createPacket(byte[] payload); @Override boolean needsAPIFrameID(); @Override boolean isBroadcast(); void setRequestID(int requestID); int getRequestID(); int getTransport(); int getFlags(); void setRequestTarget(String target); String getRequestTarget(); void setRequestData(byte[] requestData); byte[] getRequestData(); @Override LinkedHashMap<String, String> getAPIPacketParameters();  }### Answer:
@Test public final void testCreatePacketNullPayload() { byte[] payload = null; exception.expect(NullPointerException.class); exception.expectMessage(is(equalTo("Device Request packet payload cannot be null."))); DeviceRequestPacket.createPacket(payload); }
@Test public final void testCreatePacketEmptyPayload() { byte[] payload = new byte[0]; exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Incomplete Device Request packet."))); DeviceRequestPacket.createPacket(payload); }
@Test public final void testCreatePacketPayloadShorterThanNeeded() { byte[] payload = new byte[4]; payload[0] = (byte)frameType; payload[1] = (byte)requestID; payload[2] = (byte)transport; payload[3] = (byte)flags; exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Incomplete Device Request packet."))); DeviceRequestPacket.createPacket(payload); }
@Test public final void testCreatePacketPayloadNotIncludingFrameType() { byte[] payload = new byte[4 + target.length() + data.length]; payload[0] = (byte)requestID; payload[1] = (byte)transport; payload[2] = (byte)flags; payload[3] = (byte)target.length(); System.arraycopy(target.getBytes(), 0, payload, 4, target.length()); System.arraycopy(data, 0, payload, 4 + target.length(), data.length); exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Payload is not a Device Request packet."))); DeviceRequestPacket.createPacket(payload); }