/hg/icedtea-web: 2 new changesets
aazores at icedtea.classpath.org
aazores at icedtea.classpath.org
Mon May 12 13:59:46 UTC 2014
changeset f46fb24d32fb in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=f46fb24d32fb
author: Andrew Azores <aazores at redhat.com>
date: Mon May 12 09:58:28 2014 -0400
Added new tests for CacheUtil
* netx/net/sourceforge/jnlp/cache/CacheUtil.java: (urlToPath) use
StringBuilder, not StringBuffer
* tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java:
(testUrlEquals, testUrlToPath) new tests
changeset b19fe5f6a442 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=b19fe5f6a442
author: Andrew Azores <aazores at redhat.com>
date: Mon May 12 09:59:34 2014 -0400
Added new tests for FileUtils
* tests/netx/unit/net/sourceforge/jnlp/util/FileUtilsTest.java: new test
class for FileUtils
diffstat:
ChangeLog | 12 +
netx/net/sourceforge/jnlp/cache/CacheUtil.java | 4 +-
tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java | 18 ++
tests/netx/unit/net/sourceforge/jnlp/util/FileUtilsTest.java | 91 +++++++++++
4 files changed, 123 insertions(+), 2 deletions(-)
diffs (171 lines):
diff -r 69dd2eb02dbf -r b19fe5f6a442 ChangeLog
--- a/ChangeLog Fri May 09 17:30:54 2014 -0400
+++ b/ChangeLog Mon May 12 09:59:34 2014 -0400
@@ -1,3 +1,15 @@
+2014-05-09 Andrew Azores <aazores at redhat.com>
+
+ * tests/netx/unit/net/sourceforge/jnlp/util/FileUtilsTest.java: new test
+ class for FileUtils
+
+2014-05-09 Andrew Azores <aazores at redhat.com>
+
+ * netx/net/sourceforge/jnlp/cache/CacheUtil.java: (urlToPath) use
+ StringBuilder, not StringBuffer
+ * tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java:
+ (testUrlEquals, testUrlToPath) new tests
+
2014-05-09 Andrew Azores <aazores at redhat.com>
* netx/net/sourceforge/jnlp/util/TimedHashMap.java: implements Map
diff -r 69dd2eb02dbf -r b19fe5f6a442 netx/net/sourceforge/jnlp/cache/CacheUtil.java
--- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java Fri May 09 17:30:54 2014 -0400
+++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java Mon May 12 09:59:34 2014 -0400
@@ -49,9 +49,9 @@
import net.sourceforge.jnlp.runtime.ApplicationInstance;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
import net.sourceforge.jnlp.util.FileUtils;
-import net.sourceforge.jnlp.util.logging.OutputController;
import net.sourceforge.jnlp.util.PropertiesFile;
import net.sourceforge.jnlp.util.UrlUtils;
+import net.sourceforge.jnlp.util.logging.OutputController;
/**
* Provides static methods to interact with the cache, download
@@ -493,7 +493,7 @@
throw new NullPointerException();
}
- StringBuffer path = new StringBuffer();
+ StringBuilder path = new StringBuilder();
path.append(subdir);
path.append(File.separatorChar);
diff -r 69dd2eb02dbf -r b19fe5f6a442 tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java
--- a/tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java Fri May 09 17:30:54 2014 -0400
+++ b/tests/netx/unit/net/sourceforge/jnlp/cache/CacheUtilTest.java Mon May 12 09:59:34 2014 -0400
@@ -36,7 +36,9 @@
*/
package net.sourceforge.jnlp.cache;
+import java.io.File;
import java.net.URL;
+
import org.junit.Assert;
import org.junit.Test;
@@ -52,4 +54,20 @@
Assert.assertTrue("normalized form " + i + " must CacheUtil.urlEquals to its original " + i, CacheUtil.urlEquals(n[i], u[i]));
}
}
+
+ @Test
+ public void testUrlEquals() throws Exception {
+ final URL n1 = null, n2 = null, u1 = new URL("http://example.com"), u2 = u1, u3 = new URL("http://example.com");
+ Assert.assertTrue("Two nulls should be equal", CacheUtil.urlEquals(n1, n2));
+ Assert.assertFalse("Null URL should not equal a non-null", CacheUtil.urlEquals(n1, u1));
+ Assert.assertTrue("URL should equal itself (same reference)", CacheUtil.urlEquals(u1, u2));
+ Assert.assertTrue("URLs should be equal when different reference but the same URL", CacheUtil.urlEquals(u1, u3));
+ }
+
+ @Test
+ public void testUrlToPath() throws Exception {
+ final URL u = new URL("https://example.com/applet/some:weird*applet?.jar");
+ final File expected = new File("/tmp/https/example.com/applet/some_weird_applet");
+ Assert.assertEquals(expected, CacheUtil.urlToPath(u, "/tmp"));
+ }
}
diff -r 69dd2eb02dbf -r b19fe5f6a442 tests/netx/unit/net/sourceforge/jnlp/util/FileUtilsTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/FileUtilsTest.java Mon May 12 09:59:34 2014 -0400
@@ -0,0 +1,91 @@
+/* FileUtilsTest.java
+Copyright (C) 2014 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+package net.sourceforge.jnlp.util;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class FileUtilsTest {
+
+ private static final char[] INVALID = {
+ '\\',
+ '/',
+ ':',
+ '*',
+ '?',
+ '"',
+ '<',
+ '>',
+ '|', };
+ private static final char SANITIZED = '_';
+
+ @Test
+ public void testSanitizePath() throws Exception {
+ for (char ch : INVALID) {
+ String str = File.separator + "tmp" + File.separator + "test" + ch + "path";
+ String sanitized = FileUtils.sanitizePath(str);
+ assertFalse(ch + " should be sanitized from " + sanitized, ch != File.separatorChar && sanitized.contains(Character.toString(ch)));
+ assertEquals(str.replace(ch, ch == File.separatorChar ? ch : SANITIZED), sanitized);
+ }
+ }
+
+ @Test
+ public void testSanitizeFilename() throws Exception {
+ for (char ch : INVALID) {
+ String str = "file" + ch + "name";
+ String sanitized = FileUtils.sanitizeFileName(str);
+ assertFalse(ch + " should be sanitized from " + sanitized, sanitized.contains(Character.toString(ch)));
+ assertEquals(str.replace(ch, SANITIZED), sanitized);
+ }
+ }
+
+ @Test
+ public void testCreateParentDir() throws Exception {
+ final File tmpdir = new File(System.getProperty("java.io.tmpdir")), testParent = new File(tmpdir, "itw_test_create_parent_dir"), testChild = new File(testParent, "test_child_dir");
+ testChild.deleteOnExit();
+ testParent.deleteOnExit();
+ FileUtils.createParentDir(testChild);
+ assertTrue(tmpdir.isDirectory());
+ assertTrue(testParent.isDirectory());
+ assertFalse(testChild.exists());
+ }
+
+}
More information about the distro-pkg-dev
mailing list