Mercurial > hg > release > icedtea-web-1.6
changeset 997:b19fe5f6a442
Added new tests for FileUtils
* tests/netx/unit/net/sourceforge/jnlp/util/FileUtilsTest.java: new test
class for FileUtils
author | Andrew Azores <aazores@redhat.com> |
---|---|
date | Mon, 12 May 2014 09:59:34 -0400 |
parents | f46fb24d32fb |
children | c3fb4b493d78 |
files | ChangeLog tests/netx/unit/net/sourceforge/jnlp/util/FileUtilsTest.java |
diffstat | 2 files changed, 96 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon May 12 09:58:28 2014 -0400 +++ b/ChangeLog Mon May 12 09:59:34 2014 -0400 @@ -1,3 +1,8 @@ +2014-05-09 Andrew Azores <aazores@redhat.com> + + * tests/netx/unit/net/sourceforge/jnlp/util/FileUtilsTest.java: new test + class for FileUtils + 2014-05-09 Andrew Azores <aazores@redhat.com> * netx/net/sourceforge/jnlp/cache/CacheUtil.java: (urlToPath) use
--- /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()); + } + +}