Mercurial > hg > release > icedtea-web-1.4
changeset 688:b912e91204b1
Add tests for newly added UrlUtils functions
author | Adam Domurad <adomurad@redhat.com> |
---|---|
date | Tue, 23 Apr 2013 13:59:20 -0400 |
parents | 6b680fe9c390 |
children | 5c5709590a9d |
files | ChangeLog tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java |
diffstat | 2 files changed, 42 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Apr 23 13:55:23 2013 -0400 +++ b/ChangeLog Tue Apr 23 13:59:20 2013 -0400 @@ -1,3 +1,8 @@ +2013-04-23 Adam Domurad <adomurad@redhat.com> + + * tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java: + Added tests for decodeUrlQuietly, normalizeUrl, normalizeUrlQuietly. + 2013-04-23 Adam Domurad <adomurad@redhat.com> * netx/net/sourceforge/jnlp/cache/ResourceTracker.java: Remove no
--- a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java Tue Apr 23 13:55:23 2013 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java Tue Apr 23 13:59:20 2013 -0400 @@ -27,4 +27,40 @@ 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