### Question:
CoAPRequest extends CoAPMessage { public URI getUriFromRequest() throws CoAPException { try { createUriFromRequest(getSocketAddress()); } catch (CoAPException e) { return null; } return uri; } CoAPRequest(int version, CoAPMessageType messageType, CoAPRequestCode methodCode, int messageId, byte[] token);  CoAPRequest(int version, CoAPMessageType messageType, CoAPRequestCode methodCode, int messageId);  CoAPRequest(CoAPMessageType messageType, CoAPRequestCode methodCode, int messageId, byte[] token);  CoAPRequest(CoAPMessageType messageType, CoAPRequestCode methodCode, int messageId); void setUri(URI uri); void generateTokenHeader(); void createUriFromRequest(SocketAddress socketAddress); @Override CoAPRequestCode getCode(); URI getUriFromRequest(); void setListener(CoAPRequestListener listener); CoAPRequestListener getListener(); Set<CoAPOptionHeader> optionsForMatching();  }### Answer:
@Test public void testGetUriFromRequest() { URI uri = null; try { uri = req.getUriFromRequest(); assertNull(uri); } catch (CoAPException e) { e.printStackTrace(); } String path = "testPath"; req.addOptionHeader(hostOpt); req.addOptionHeader(portOpt); CoAPOptionHeader pathOpt = new CoAPOptionHeader( CoAPOptionName.URI_PATH, path.getBytes()); req.addOptionHeader(pathOpt); try { uri = req.getUriFromRequest(); assertNotNull(uri); assert uri.getPort() == port; assertEquals(uri.getHost(), host); assertEquals(uri.getPath(), "/" + path); boolean remove = req.removeOptionHeader(pathOpt); assertTrue(remove); remove = req.removeOptionHeader(pathOpt); assertFalse(remove); path = "/testPath"; pathOpt = new CoAPOptionHeader(CoAPOptionName.URI_PATH, path.getBytes()); req.addOptionHeader(pathOpt); assertEquals(uri.getPath(), path); req.removeOptionHeader(pathOpt); path = "/testPath/notvalid"; pathOpt = new CoAPOptionHeader(CoAPOptionName.URI_PATH, path.getBytes()); assertFalse(req.addOptionHeader(pathOpt)); assertEquals(0, req.getOptionHeaders(CoAPOptionName.URI_PATH) .size()); String firstPart = "/firstPart"; pathOpt = new CoAPOptionHeader(CoAPOptionName.URI_PATH, firstPart.getBytes()); req.addOptionHeader(pathOpt); String secondPart = "secondPart"; pathOpt = new CoAPOptionHeader(CoAPOptionName.URI_PATH, secondPart.getBytes()); req.addOptionHeader(pathOpt); uri = req.getUriFromRequest(); assertEquals(firstPart + "/" + secondPart, uri.getPath()); req.removeOptionHeader(pathOpt); secondPart = "/secondPart"; pathOpt = new CoAPOptionHeader(CoAPOptionName.URI_PATH, secondPart.getBytes()); req.addOptionHeader(pathOpt); uri = req.getUriFromRequest(); assertEquals(firstPart + secondPart, uri.getPath()); } catch (CoAPException e) { e.printStackTrace(); } }