2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.io.IOException;
25 import java.util.List;
27 import org.testng.Assert;
28 import org.testng.annotations.DataProvider;
29 import org.testng.annotations.Test;
32 public class FileUtilsTest
34 @Test(groups = "Functional", dataProvider = "patternsAndMinNumFiles")
35 public void testJavaFileGlob(String pattern, int atLeast, int atMost)
37 List<File> files = FileUtils.getFilesFromGlob(pattern);
40 Assert.assertTrue(files.size() > atLeast,
41 "Did not find more than " + atLeast + " files with " + pattern
42 + " (found " + files.size() + ")");
46 Assert.assertTrue(files.size() > atLeast,
47 "Did not find more than " + atLeast + " files with " + pattern
48 + " (found " + files.size() + ")");
52 Assert.assertTrue(files.size() < atMost,
53 "Did not find fewer than " + atMost + " files with " + pattern
54 + " (found " + files.size() + ")");
58 @Test(groups = "Functional", dataProvider = "dirnamesAndBasenames")
59 public void testDirnamesAndBasenames(String filename, String dirname,
60 String endsWith, String basename, String notInDirname)
62 File file = new File(filename);
63 String d = FileUtils.getDirname(file);
64 String b = FileUtils.getBasename(file);
65 Assert.assertEquals(b, basename);
66 Assert.assertTrue(d.startsWith(dirname), "getDirname(" + file.getPath()
67 + ")=" + d + " didn't start with '" + dirname + "'");
68 Assert.assertTrue(d.endsWith(endsWith), "getDirname(" + file.getPath()
69 + ")=" + d + " didn't end with '" + endsWith + "'");
71 // ensure dirname doesn't end with basename (which means you can't use same
72 // filename as dir in tests!)
73 Assert.assertFalse(d.endsWith(b), "Processed dirname '" + d
74 + "' ends with '" + b + "' when it shouldn't");
76 if (notInDirname != null)
77 Assert.assertFalse(d.contains(notInDirname), "Processed directory '"
78 + d + "' contains '" + notInDirname + "' when it shouldn't");
81 @DataProvider(name = "patternsAndMinNumFiles")
82 public Object[][] patternsAndMinNumFiles()
84 return new Object[][] { { "src/**/*.java", 900, 100000 },
85 { "src/**.java", 900, 100000 },
86 { "test/**/*.java", 250, 2500 },
87 { "test/**.java", 250, 2500 },
88 { "help/**/*.html", 100, 1000 },
89 { "test/**/F*.java", 15, 150 },
90 { "test/jalview/*/F*.java", 10, 15 }, // 12 at time of writing
91 { "test/jalview/**/F*.java", 18, 30 }, // 20 at time of writing
92 { "test/jalview/util/F**.java", 1, 5 }, // 2 at time of writing
93 { "src/jalview/b*/*.java", 14, 19 }, // 15 at time of writing
94 { "src/jalview/b**/*.java", 20, 25 }, // 22 at time of writing
98 @DataProvider(name = "dirnamesAndBasenames")
99 public Object[][] dirnamesAndBasenames()
101 String homeDir = null;
104 homeDir = new File(System.getProperty("user.home"))
106 } catch (IOException e)
108 System.err.println("Problem getting canonical home dir");
111 return new Object[][] { // -1=startsWith, 0=equals, 1=endsWith
112 { "~/hello/sailor", homeDir, "/hello", "sailor", "~" }, //
113 { "./examples/uniref50.fa", "./", "examples", "uniref50", "Users" }, //
114 { "./examples/uniref50.1.fa", "./", "examples", "uniref50.1",
116 { "examples/uniref50.fa", "examples", "examples", "uniref50",
121 @Test(groups = "Functional", dataProvider = "convertWildcardsToPathData")
122 public void convertWildcardsToPathTest(String value, String wildcard,
123 String dirname, String basename, String path)
127 FileUtils.convertWildcardsToPath(value, wildcard, dirname,
129 path, "Conversion of wildcard output path is not right.");
133 @DataProvider(name = "convertWildcardsToPathData")
134 public Object[][] convertWildcardsToPathData()
136 return new Object[][] {
139 * Arg (null if only testing headless)
140 * String value if there is one (null otherwise)
141 * boolean value if String value is null
142 * expected value of isHeadless()
146 { "*/*", "*", "{dirname}", "{basename}", "{dirname}/{basename}" },
147 { "*/", "*", "{dirname}", "{basename}", "{dirname}/" },
148 { "/*", "*", "{dirname}", "{basename}", "/{basename}" },
149 { "*", "*", "{dirname}", "{basename}", "{basename}" },
150 { "tmp/output/*/file-*.stk", "*", "{dirname}", "{basename}",
151 "tmp/output/{dirname}/file-{basename}.stk" },
152 { "/*.file", "*", "{dirname}", "{basename}", "/{basename}.file" },
153 { "*/file.stk", "*", "{dirname}", "{basename}",
154 "{dirname}/file.stk" },
155 { "tmp/abc*def/file.stk", "*", "{dirname}", "{basename}",
156 "tmp/abc{dirname}def/file.stk" },
157 { "a*b/c*d", "*", "{dirname}", "{basename}",
158 "a{dirname}b/c{basename}d" },
159 { "a*b/c", "*", "{dirname}", "{basename}", "a{dirname}b/c" },
160 { "a/b*c", "*", "{dirname}", "{basename}", "a/b{basename}c" },
161 { "a*b", "*", "{dirname}", "{basename}", "a{basename}b" },
162 { "aSTARb/cSTARd", "STAR", "BEFORE", "AFTER", "aBEFOREb/cAFTERd" },
163 { "aSTARb/c", "STAR", "BEFORE", "AFTER", "aBEFOREb/c" },
164 { "a/bSTARc", "STAR", "BEFORE", "AFTER", "a/bAFTERc" },
165 { "aSTARb", "STAR", "BEFORE", "AFTER", "aAFTERb" },