@Test public void testDecode() { Assert.assertEquals("Incorrectly decoded null string", null, WebUtilities.decode(null)); Assert.assertEquals("Incorrectly decoded empty string", "", WebUtilities.decode("")); Assert.assertEquals("Incorrectly decoded 1 char string", "x", WebUtilities.decode("x")); Assert.assertEquals("Incorrectly decoded 1 special char string", "&", WebUtilities.decode( "&")); Assert.assertEquals("Incorrectly decoded open bracket", "{", WebUtilities.decode("{")); Assert.assertEquals("Incorrectly decoded close bracket", "}", WebUtilities.decode("}")); String in = "Hello world greater> less< amper& quote""; String expected = "Hello world greater> less< amper& quote\""; Assert.assertEquals("Incorrectly decoded value", expected, WebUtilities.decode(in)); // Finally, check a encode/decode pair String encoded = WebUtilities.encode(expected); Assert.assertEquals("Incorrectly encoded/decoded value", expected, WebUtilities.decode( encoded)); }
/** * We need to match urls which include a random no-cache value. e.g. * <pre>unknown?no-cache=1994285646-4&target_id=L&s=0</pre> * * @param image the image to test. * * @throws IOException an IO exception * @throws SAXException a SAX exception * @throws XpathException an xpath exception */ private void assertSrcMatch(final WImage image) throws IOException, SAXException, XpathException { final String noCacheRegexp = "no-cache=[^&]*"; String src = WebUtilities.decode(image.getTargetUrl()); String expectedSrc = src.replaceFirst(noCacheRegexp, ""); String actualSrc = evaluateXPath(image, "//html:img/@src").replaceFirst(noCacheRegexp, ""); Assert.assertEquals("Incorrect source url", expectedSrc, actualSrc); }