### Question:
Handler extends URLStreamHandler { public URLConnection openConnection(URL someUrl) { return new URLConnection(someUrl) { public void connect() { LOG.fine("connect"); } public InputStream getInputStream() throws java.io.IOException { LOG.fine("getInputStream, path=" + url.getPath()); InputStream is = Handler.class.getClassLoader().getResourceAsStream(url.getPath()); if (is == null) { throw new java.io.IOException(url.getPath() + " Not Found by getResourceAsStream(), ClassLoader=" + Handler.class.getClassLoader()); } return is; } }; }  URLConnection openConnection(URL someUrl);  }### Answer:
@Test public void testGetStreamToThisResource() throws Exception { String urlpath = HandlerTest.class.getName().replace('.', '/') + ".class"; String urls = "resourceadapter:" + urlpath; URL res = new URL(null, urls, h); InputStream is = h.openConnection(res).getInputStream(); assertNotNull("stream is not null", is); }
@Test public void testGetStreamToThisResource() throws Exception { String urlpath = HandlerTest.class.getName().replace('.', '/') + ".class"; String urls = "resourceadapter:" + urlpath; URL res = new URL(null, urls, h); InputStream is = h.openConnection(res).getInputStream(); assertTrue("stream is not null", is != null); }
@Test public void testGetStreamToNonExistantResourceThrows() throws Exception { String path = "some gobbledy rubbish/that/does/not/exist"; String urls = "resourceadapter:" + path; URL res = new URL(null, urls, h); try { h.openConnection(res).getInputStream(); fail("expect IOException on non existant url"); } catch (IOException ioe) { String msg = ioe.getMessage(); assertTrue("Ex message has expected text, msg=" + msg, msg.indexOf(path) != -1); } }