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.util.List;
26 import org.testng.Assert;
27 import org.testng.annotations.DataProvider;
28 import org.testng.annotations.Test;
31 public class FileUtilsTest
33 @Test(groups = "Functional", dataProvider = "patternsAndMinNumFiles")
34 public void testJavaFileGlob(String pattern, int atLeast, int atMost)
36 List<File> files = FileUtils.getFilesFromGlob(pattern);
39 Assert.assertTrue(files.size() > atLeast,
40 "Did not find more than " + atLeast + " files with " + pattern
41 + " (found " + files.size() + ")");
45 Assert.assertTrue(files.size() > atLeast,
46 "Did not find more than " + atLeast + " files with " + pattern
47 + " (found " + files.size() + ")");
51 Assert.assertTrue(files.size() < atMost,
52 "Did not find fewer than " + atMost + " files with " + pattern
53 + " (found " + files.size() + ")");
57 @Test(groups = "Functional", dataProvider = "dirnamesAndBasenames")
58 public void testDirnamesAndBasenames(String filename, int where,
59 String dirname, String basename)
61 File file = new File(filename);
62 String d = FileUtils.getDirname(file);
63 String b = FileUtils.getBasename(file);
64 Assert.assertEquals(b, basename);
66 Assert.assertEquals(d, dirname);
68 Assert.assertTrue(d.startsWith(dirname),
69 "getDirname(" + file.getPath() + ")=" + d
70 + " didn't start with '" + d + "'");
72 Assert.assertTrue(d.endsWith(dirname), "getDirname(" + file.getPath()
73 + ")=" + d + " didn't end with '" + d + "'");
76 @DataProvider(name = "patternsAndMinNumFiles")
77 public Object[][] patternsAndMinNumFiles()
79 return new Object[][] { { "src/**/*.java", 900, 100000 },
80 { "src/**.java", 900, 100000 },
81 { "test/**/*.java", 250, 2500 },
82 { "test/**.java", 250, 2500 },
83 { "help/**/*.html", 100, 1000 },
84 { "test/**/F*.java", 15, 150 },
85 { "test/jalview/*/F*.java", 10, 15 }, // 12 at time of writing
86 { "test/jalview/**/F*.java", 18, 30 }, // 20 at time of writing
87 { "test/jalview/util/F**.java", 1, 5 }, // 2 at time of writing
88 { "src/jalview/b*/*.java", 14, 19 }, // 15 at time of writing
89 { "src/jalview/b**/*.java", 20, 25 }, // 22 at time of writing
93 @DataProvider(name = "dirnamesAndBasenames")
94 public Object[][] dirnamesAndBasenames()
96 return new Object[][] { // -1=startsWith, 0=equals, 1=endsWith
97 { "~/hello/sailor", -1, System.getProperty("user.home"), "sailor" }, //
98 { "~/hello/sailor", 1, "/hello", "sailor" }, //
99 { "./examples/uniref50.fa", -1, "/", "uniref50" }, //
100 { "./examples/uniref50.fa", 1, "/examples", "uniref50" }, //
101 { "examples/uniref50.fa", 1, "/examples", "uniref50" }, //