diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java | 38 |
2 files changed, 42 insertions, 1 deletions
@@ -1,5 +1,10 @@ 2013-04-23 Adam Domurad <[email protected]> + * tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java: + Added tests for decodeUrlQuietly, normalizeUrl, normalizeUrlQuietly. + +2013-04-23 Adam Domurad <[email protected]> + * netx/net/sourceforge/jnlp/cache/ResourceTracker.java: Remove no longer used constants. Remove (normalizeUrl). Update calls. * netx/net/sourceforge/jnlp/cache/CacheUtil.java: Expand imports. diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java index bd0ef17..1a0e69c 100644 --- a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java +++ b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java @@ -27,4 +27,40 @@ public class UrlUtilsTest { assertEquals("http://example.com/%20test%20test", UrlUtils.normalizeUrlAndStripParams(new URL("http://example.com/ test%20test ?test=test")).toString()); } -} + + @Test + public void testDecodeUrlQuietly() throws Exception { + // This is a wrapper over URLDecoder.decode, simple test suffices + assertEquals("http://example.com/ test test", + UrlUtils.decodeUrlQuietly(new URL("http://example.com/%20test%20test")).toString()); + } + + @Test + public void testNormalizeUrl() throws Exception { + boolean[] encodeFileUrlPossiblities = {false, true}; + + // encodeFileUrl flag should have no effect on non-file URLs, but let's be sure. + for (boolean encodeFileUrl : encodeFileUrlPossiblities ) { + // Test URL with no previous encoding + assertEquals("http://example.com/%20test", + UrlUtils.normalizeUrl(new URL("http://example.com/ test"), encodeFileUrl).toString()); + // Test partially encoded URL with trailing spaces + assertEquals("http://example.com/%20test%20test", + UrlUtils.normalizeUrl(new URL("http://example.com/ test%20test "), encodeFileUrl).toString()); + } + + // Test file URL with file URL encoding turned off + assertFalse("file://example/%20test".equals( + UrlUtils.normalizeUrl(new URL("file://example/ test"), false).toString())); + + // Test file URL with file URL encoding turned on + assertEquals("file://example/%20test", + UrlUtils.normalizeUrl(new URL("file://example/ test"), true).toString()); + } + @Test + public void testNormalizeUrlQuietly() throws Exception { + // This is a wrapper over UrlUtils.normalizeUrl(), simple test suffices + assertEquals("http://example.com/%20test%20test", + UrlUtils.normalizeUrl(new URL("http://example.com/ test%20test ")).toString()); + } +}
\ No newline at end of file |