### Question:
GenericURLFactory implements URLStreamHandlerFactory { @SuppressWarnings("unchecked") public URLStreamHandler createURLStreamHandler(String protocol) { Class<? extends URLConnection> c = null; if (!urlConnections.containsKey(protocol)) { logger.info("No protocol mapping with '{}' found. Return null. Creating...", protocol); return null; } try { c = (Class<? extends URLConnection>) Class.forName(urlConnections.get(protocol)); } catch (ClassNotFoundException e) { logger.error("Class not found for protocol '{}' and return null. Error message: '{}'", protocol, e.getMessage()); return null; } return new GenericURLStreamHandler(c, urlDefaultPorts.get(protocol)); } private  GenericURLFactory(); static void initialize(); static GenericURLFactory getInstance(); void addURLConnection(String protocol, String classname, int defaultPort); void addURLConnection(String protocol, String classname); void removeURLConnection(String protocol); HashMap<String, String> getURLConnections(); @SuppressWarnings("unchecked") URLStreamHandler createURLStreamHandler(String protocol);  }### Answer:
@Test public void testCreateURLStreamHandler() { m_genericURLFactory.addURLConnection("testprotocol", "org.opennms.core.utils.url.StubGenericURLConnection"); m_genericURLFactory.addURLConnection("noclass", "org.opennms.bkd.class.not.found"); Assert.assertEquals("Test get test protocol class", m_genericURLFactory.createURLStreamHandler("testprotocol").getClass().getName(), "org.opennms.core.utils.url.GenericURLStreamHandler"); Assert.assertNull(m_genericURLFactory.createURLStreamHandler("undefined_protocol")); Assert.assertNull(m_genericURLFactory.createURLStreamHandler("noclass")); }