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, int where,
60 String dirname, 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);
67 Assert.assertEquals(d, dirname);
69 Assert.assertTrue(d.startsWith(dirname),
70 "getDirname(" + file.getPath() + ")=" + d
71 + " didn't start with '" + dirname + "'");
73 Assert.assertTrue(d.endsWith(dirname), "getDirname(" + file.getPath()
74 + ")=" + d + " didn't end with '" + d + "'");
76 // ensure dirname doesn't end with basename (which means you can't use same
77 // filename as dir in tests!)
78 Assert.assertFalse(d.endsWith(b));
80 if (notInDirname != null)
81 Assert.assertFalse(d.contains(notInDirname));
84 @DataProvider(name = "patternsAndMinNumFiles")
85 public Object[][] patternsAndMinNumFiles()
87 return new Object[][] { { "src/**/*.java", 900, 100000 },
88 { "src/**.java", 900, 100000 },
89 { "test/**/*.java", 250, 2500 },
90 { "test/**.java", 250, 2500 },
91 { "help/**/*.html", 100, 1000 },
92 { "test/**/F*.java", 15, 150 },
93 { "test/jalview/*/F*.java", 10, 15 }, // 12 at time of writing
94 { "test/jalview/**/F*.java", 18, 30 }, // 20 at time of writing
95 { "test/jalview/util/F**.java", 1, 5 }, // 2 at time of writing
96 { "src/jalview/b*/*.java", 14, 19 }, // 15 at time of writing
97 { "src/jalview/b**/*.java", 20, 25 }, // 22 at time of writing
101 @DataProvider(name = "dirnamesAndBasenames")
102 public Object[][] dirnamesAndBasenames()
104 String homeDir = null;
107 homeDir = new File(System.getProperty("user.home"))
109 } catch (IOException e)
111 System.err.println("Problem getting canonical home dir");
114 return new Object[][] { // -1=startsWith, 0=equals, 1=endsWith
115 { "~/hello/sailor", -1, homeDir, "sailor", "~" }, //
116 { "~/hello/sailor", 1, "/hello", "sailor", "~" }, //
117 { "./examples/uniref50.fa", -1, "/", "uniref50", "." }, //
118 { "./examples/uniref50.fa", 1, "/examples", "uniref50", "." }, //
119 { "examples/uniref50.fa", 1, "/examples", "uniref50", ".fa" }, //