X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FFileUtilsTest.java;h=3cc9ca6abe8386ce3321292c9fdee033e8737711;hb=e83ce5d8ef826fc0b509a51f154abdf734501077;hp=79c703fac289ca319c64cb36d6a2fe9582afbacb;hpb=82927e58aa86abee1ab11da889cabbebb18e90ad;p=jalview.git diff --git a/test/jalview/util/FileUtilsTest.java b/test/jalview/util/FileUtilsTest.java index 79c703f..3cc9ca6 100644 --- a/test/jalview/util/FileUtilsTest.java +++ b/test/jalview/util/FileUtilsTest.java @@ -21,7 +21,6 @@ package jalview.util; import java.io.File; -import java.io.IOException; import java.util.List; import org.testng.Assert; @@ -56,29 +55,26 @@ public class FileUtilsTest } @Test(groups = "Functional", dataProvider = "dirnamesAndBasenames") - public void testDirnamesAndBasenames(String filename, int where, - String dirname, String basename, String notInDirname) + public void testDirnamesAndBasenames(String filename, String dirname, + String endsWith, String basename, String notInDirname) { File file = new File(filename); String d = FileUtils.getDirname(file); String b = FileUtils.getBasename(file); Assert.assertEquals(b, basename); - if (where == 0) - Assert.assertEquals(d, dirname); - else if (where < 0) - Assert.assertTrue(d.startsWith(dirname), - "getDirname(" + file.getPath() + ")=" + d - + " didn't start with '" + dirname + "'"); - else if (where > 0) - Assert.assertTrue(d.endsWith(dirname), "getDirname(" + file.getPath() - + ")=" + d + " didn't end with '" + d + "'"); + Assert.assertTrue(d.startsWith(dirname), "getDirname(" + file.getPath() + + ")=" + d + " didn't start with '" + dirname + "'"); + Assert.assertTrue(d.endsWith(endsWith), "getDirname(" + file.getPath() + + ")=" + d + " didn't end with '" + endsWith + "'"); // ensure dirname doesn't end with basename (which means you can't use same // filename as dir in tests!) - Assert.assertFalse(d.endsWith(b)); + Assert.assertFalse(d.endsWith(b), "Processed dirname '" + d + + "' ends with '" + b + "' when it shouldn't"); if (notInDirname != null) - Assert.assertFalse(d.contains(notInDirname)); + Assert.assertFalse(d.contains(notInDirname), "Processed directory '" + + d + "' contains '" + notInDirname + "' when it shouldn't"); } @DataProvider(name = "patternsAndMinNumFiles") @@ -101,22 +97,114 @@ public class FileUtilsTest @DataProvider(name = "dirnamesAndBasenames") public Object[][] dirnamesAndBasenames() { - String homeDir = null; - try - { - homeDir = new File(System.getProperty("user.home")) - .getCanonicalPath(); - } catch (IOException e) - { - System.err.println("Problem getting canonical home dir"); - e.printStackTrace(); - } + String homeDir = new File(System.getProperty("user.home")).getPath(); return new Object[][] { // -1=startsWith, 0=equals, 1=endsWith - { "~/hello/sailor", -1, homeDir, "sailor", "~" }, // - { "~/hello/sailor", 1, "/hello", "sailor", "~" }, // - { "./examples/uniref50.fa", -1, "/", "uniref50", null }, // - { "./examples/uniref50.fa", 1, "/examples", "uniref50", null }, // - { "examples/uniref50.fa", 1, "/examples", "uniref50", null }, // + { "~/hello/sailor", homeDir, "/hello", "sailor", "~" }, // + { "./examples/uniref50.fa", "./", "examples", "uniref50", "Users" }, // + { "./examples/uniref50.1.fa", "./", "examples", "uniref50.1", + "Users" }, // + { "examples/uniref50.fa", "examples", "examples", "uniref50", + ".fa" }, // + }; + } + + @Test(groups = "Functional", dataProvider = "convertWildcardsToPathData") + public void convertWildcardsToPathTest(String value, String wildcard, + String dirname, String basename, String path) + { + + Assert.assertEquals( + FileUtils.convertWildcardsToPath(value, wildcard, dirname, + basename), + path, "Conversion of wildcard output path is not right."); + + } + + @DataProvider(name = "convertWildcardsToPathData") + public Object[][] convertWildcardsToPathData() + { + return new Object[][] { + /* + * cmdline args + * Arg (null if only testing headless) + * String value if there is one (null otherwise) + * boolean value if String value is null + * expected value of isHeadless() + */ + /* + */ + { "*/*", "*", "{dirname}", "{basename}", "{dirname}/{basename}" }, + { "*/", "*", "{dirname}", "{basename}", "{dirname}/" }, + { "/*", "*", "{dirname}", "{basename}", "/{basename}" }, + { "*", "*", "{dirname}", "{basename}", "{basename}" }, + { "tmp/output/*/file-*.stk", "*", "{dirname}", "{basename}", + "tmp/output/{dirname}/file-{basename}.stk" }, + { "/*.file", "*", "{dirname}", "{basename}", "/{basename}.file" }, + { "*/file.stk", "*", "{dirname}", "{basename}", + "{dirname}/file.stk" }, + { "tmp/abc*def/file.stk", "*", "{dirname}", "{basename}", + "tmp/abc{dirname}def/file.stk" }, + { "a*b/c*d", "*", "{dirname}", "{basename}", + "a{dirname}b/c{basename}d" }, + { "a*b/c", "*", "{dirname}", "{basename}", "a{dirname}b/c" }, + { "a/b*c", "*", "{dirname}", "{basename}", "a/b{basename}c" }, + { "a*b", "*", "{dirname}", "{basename}", "a{basename}b" }, + { "aSTARb/cSTARd", "STAR", "BEFORE", "AFTER", "aBEFOREb/cAFTERd" }, + { "aSTARb/c", "STAR", "BEFORE", "AFTER", "aBEFOREb/c" }, + { "a/bSTARc", "STAR", "BEFORE", "AFTER", "a/bAFTERc" }, + { "aSTARb", "STAR", "BEFORE", "AFTER", "aAFTERb" }, + // + }; + } + + @Test( + groups = "Functional", + dataProvider = "stringFilenamesBaseAndExtensionsData") + public void stringGetBaseAndExtensionTest(String filename, + String extension, String base) + { + String thisBase = FileUtils.getBase(filename); + Assert.assertEquals(thisBase, base, + "base part of path and filename not as expected"); + String thisExtension = FileUtils.getExtension(filename); + Assert.assertEquals(thisExtension, extension, + "extension part of filename not as expected"); + } + + @DataProvider(name = "stringFilenamesBaseAndExtensionsData") + public Object[][] stringFilenamesBaseAndExtensionsData() + { + return new Object[][] { + /* + * String full URL or path + * String base the above but without the extension if there is one + * String extension the filename extension if there is one + */ + /* + */ + { "/examples/uniref50.fa", "fa", "/examples/uniref50." }, + { "/examples/uniref50", null, "/examples/uniref50" }, + { "/examples/.uniref50", null, "/examples/.uniref50" }, + { "/exampl.es/uniref50", null, "/exampl.es/uniref50" }, + { "/examples/uniref50.", "", "/examples/uniref50." }, + { "examples/uniref50.fa", "fa", "examples/uniref50." }, + { "examples/uniref50", null, "examples/uniref50" }, + { "examples/.uniref50", null, "examples/.uniref50" }, + { "exampl.es/uniref50", null, "exampl.es/uniref50" }, + { "examples/uniref50.", "", "examples/uniref50." }, + { "https://www.jalview.org:443/examples/uniref50.fa", "fa", + "https://www.jalview.org:443/examples/uniref50." }, + { "https://www.jalview.org:443/examples/uniref50", null, + "https://www.jalview.org:443/examples/uniref50" }, + { "https://www.jalview.org:443/examples/.uniref50", null, + "https://www.jalview.org:443/examples/.uniref50" }, + { "https://www.jalview.org:443/exampl.es/uniref50", null, + "https://www.jalview.org:443/exampl.es/uniref50" }, + { "https://www.jalview.org:443/examples/uniref50.", "", + "https://www.jalview.org:443/examples/uniref50." }, + /* + */ + // }; } }