1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import java.io.File; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.testng.Assert; |
27 |
|
import org.testng.annotations.DataProvider; |
28 |
|
import org.testng.annotations.Test; |
29 |
|
|
30 |
|
@Test |
|
|
| 90.5% |
Uncovered Elements: 4 (42) |
Complexity: 12 |
Complexity Density: 0.46 |
|
31 |
|
public class FileUtilsTest |
32 |
|
{ |
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
1PASS
|
|
33 |
11 |
@Test(groups = "Functional", dataProvider = "patternsAndMinNumFiles")... |
34 |
|
public void testJavaFileGlob(String pattern, int atLeast, int atMost) |
35 |
|
{ |
36 |
11 |
List<File> files = FileUtils.getFilesFromGlob(pattern); |
37 |
11 |
if (atLeast != -1) |
38 |
|
{ |
39 |
11 |
Assert.assertTrue(files.size() > atLeast, |
40 |
|
"Did not find more than " + atLeast + " files with " + pattern |
41 |
|
+ " (found " + files.size() + ")"); |
42 |
|
} |
43 |
11 |
if (atLeast != -1) |
44 |
|
{ |
45 |
11 |
Assert.assertTrue(files.size() > atLeast, |
46 |
|
"Did not find more than " + atLeast + " files with " + pattern |
47 |
|
+ " (found " + files.size() + ")"); |
48 |
|
} |
49 |
11 |
if (atMost != -1) |
50 |
|
{ |
51 |
11 |
Assert.assertTrue(files.size() < atMost, |
52 |
|
"Did not find fewer than " + atMost + " files with " + pattern |
53 |
|
+ " (found " + files.size() + ")"); |
54 |
|
} |
55 |
|
} |
56 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
1PASS
|
|
57 |
4 |
@Test(groups = "Functional", dataProvider = "dirnamesAndBasenames")... |
58 |
|
public void testDirnamesAndBasenames(String filename, String dirname, |
59 |
|
String endsWith, String basename, String notInDirname) |
60 |
|
{ |
61 |
4 |
File file = new File(filename); |
62 |
4 |
String d = FileUtils.getDirname(file); |
63 |
4 |
String b = FileUtils.getBasename(file); |
64 |
4 |
Assert.assertEquals(b, basename); |
65 |
4 |
Assert.assertTrue(d.startsWith(dirname), "getDirname(" + file.getPath() |
66 |
|
+ ")=" + d + " didn't start with '" + dirname + "'"); |
67 |
4 |
Assert.assertTrue(d.endsWith(endsWith), "getDirname(" + file.getPath() |
68 |
|
+ ")=" + d + " didn't end with '" + endsWith + "'"); |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
4 |
Assert.assertFalse(d.endsWith(b), "Processed dirname '" + d |
73 |
|
+ "' ends with '" + b + "' when it shouldn't"); |
74 |
|
|
75 |
4 |
if (notInDirname != null) |
76 |
4 |
Assert.assertFalse(d.contains(notInDirname), "Processed directory '" |
77 |
|
+ d + "' contains '" + notInDirname + "' when it shouldn't"); |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@return |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
1 |
@DataProvider(name = "patternsAndMinNumFiles")... |
86 |
|
public Object[][] patternsAndMinNumFiles() |
87 |
|
{ |
88 |
1 |
return new Object[][] { { "src/**/*.java", 900, 100000 }, |
89 |
|
{ "src/**.java", 900, 100000 }, |
90 |
|
{ "test/**/*.java", 250, 2500 }, |
91 |
|
{ "test/**.java", 250, 2500 }, |
92 |
|
{ "help/**/*.html", 100, 1000 }, |
93 |
|
{ "test/**/F*.java", 15, 150 }, |
94 |
|
{ "test/jalview/*/F*.java", 10, 15 }, |
95 |
|
{ "test/jalview/**/F*.java", 18, 30 }, |
96 |
|
{ "test/jalview/util/F**.java", 1, 5 }, |
97 |
|
{ "src/jalview/b*/*.java", 14, 19 }, |
98 |
|
{ "src/jalview/b**/*.java", 23, 26 }, |
99 |
|
}; |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
102 |
1 |
@DataProvider(name = "dirnamesAndBasenames")... |
103 |
|
public Object[][] dirnamesAndBasenames() |
104 |
|
{ |
105 |
1 |
String homeDir = new File(System.getProperty("user.home")).getPath(); |
106 |
1 |
return new Object[][] { |
107 |
|
{ "~/hello/sailor", homeDir, "/hello", "sailor", "~" }, |
108 |
|
{ "./examples/uniref50.fa", "./", "examples", "uniref50", "Users" }, |
109 |
|
{ "./examples/uniref50.1.fa", "./", "examples", "uniref50.1", |
110 |
|
"Users" }, |
111 |
|
{ "examples/uniref50.fa", "examples", "examples", "uniref50", |
112 |
|
".fa" }, |
113 |
|
}; |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
116 |
16 |
@Test(groups = "Functional", dataProvider = "convertWildcardsToPathData")... |
117 |
|
public void convertWildcardsToPathTest(String value, String wildcard, |
118 |
|
String dirname, String basename, String path) |
119 |
|
{ |
120 |
|
|
121 |
16 |
Assert.assertEquals( |
122 |
|
FileUtils.convertWildcardsToPath(value, wildcard, dirname, |
123 |
|
basename), |
124 |
|
path, "Conversion of wildcard output path is not right."); |
125 |
|
|
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
1 |
@DataProvider(name = "convertWildcardsToPathData")... |
129 |
|
public Object[][] convertWildcardsToPathData() |
130 |
|
{ |
131 |
1 |
return new Object[][] { |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
{ "*/*", "*", "{dirname}", "{basename}", "{dirname}/{basename}" }, |
142 |
|
{ "*/", "*", "{dirname}", "{basename}", "{dirname}/" }, |
143 |
|
{ "/*", "*", "{dirname}", "{basename}", "/{basename}" }, |
144 |
|
{ "*", "*", "{dirname}", "{basename}", "{basename}" }, |
145 |
|
{ "tmp/output/*/file-*.stk", "*", "{dirname}", "{basename}", |
146 |
|
"tmp/output/{dirname}/file-{basename}.stk" }, |
147 |
|
{ "/*.file", "*", "{dirname}", "{basename}", "/{basename}.file" }, |
148 |
|
{ "*/file.stk", "*", "{dirname}", "{basename}", |
149 |
|
"{dirname}/file.stk" }, |
150 |
|
{ "tmp/abc*def/file.stk", "*", "{dirname}", "{basename}", |
151 |
|
"tmp/abc{dirname}def/file.stk" }, |
152 |
|
{ "a*b/c*d", "*", "{dirname}", "{basename}", |
153 |
|
"a{dirname}b/c{basename}d" }, |
154 |
|
{ "a*b/c", "*", "{dirname}", "{basename}", "a{dirname}b/c" }, |
155 |
|
{ "a/b*c", "*", "{dirname}", "{basename}", "a/b{basename}c" }, |
156 |
|
{ "a*b", "*", "{dirname}", "{basename}", "a{basename}b" }, |
157 |
|
{ "aSTARb/cSTARd", "STAR", "BEFORE", "AFTER", "aBEFOREb/cAFTERd" }, |
158 |
|
{ "aSTARb/c", "STAR", "BEFORE", "AFTER", "aBEFOREb/c" }, |
159 |
|
{ "a/bSTARc", "STAR", "BEFORE", "AFTER", "a/bAFTERc" }, |
160 |
|
{ "aSTARb", "STAR", "BEFORE", "AFTER", "aAFTERb" }, |
161 |
|
|
162 |
|
}; |
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
165 |
15 |
@Test(... |
166 |
|
groups = "Functional", |
167 |
|
dataProvider = "stringFilenamesBaseAndExtensionsData") |
168 |
|
public void stringGetBaseAndExtensionTest(String filename, |
169 |
|
String extension, String base) |
170 |
|
{ |
171 |
15 |
String thisBase = FileUtils.getBase(filename); |
172 |
15 |
Assert.assertEquals(thisBase, base, |
173 |
|
"base part of path and filename not as expected"); |
174 |
15 |
String thisExtension = FileUtils.getExtension(filename); |
175 |
15 |
Assert.assertEquals(thisExtension, extension, |
176 |
|
"extension part of filename not as expected"); |
177 |
|
} |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
179 |
1 |
@DataProvider(name = "stringFilenamesBaseAndExtensionsData")... |
180 |
|
public Object[][] stringFilenamesBaseAndExtensionsData() |
181 |
|
{ |
182 |
1 |
return new Object[][] { |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
{ "/examples/uniref50.fa", "fa", "/examples/uniref50." }, |
191 |
|
{ "/examples/uniref50", null, "/examples/uniref50" }, |
192 |
|
{ "/examples/.uniref50", null, "/examples/.uniref50" }, |
193 |
|
{ "/exampl.es/uniref50", null, "/exampl.es/uniref50" }, |
194 |
|
{ "/examples/uniref50.", "", "/examples/uniref50." }, |
195 |
|
{ "examples/uniref50.fa", "fa", "examples/uniref50." }, |
196 |
|
{ "examples/uniref50", null, "examples/uniref50" }, |
197 |
|
{ "examples/.uniref50", null, "examples/.uniref50" }, |
198 |
|
{ "exampl.es/uniref50", null, "exampl.es/uniref50" }, |
199 |
|
{ "examples/uniref50.", "", "examples/uniref50." }, |
200 |
|
{ "https://www.jalview.org:443/examples/uniref50.fa", "fa", |
201 |
|
"https://www.jalview.org:443/examples/uniref50." }, |
202 |
|
{ "https://www.jalview.org:443/examples/uniref50", null, |
203 |
|
"https://www.jalview.org:443/examples/uniref50" }, |
204 |
|
{ "https://www.jalview.org:443/examples/.uniref50", null, |
205 |
|
"https://www.jalview.org:443/examples/.uniref50" }, |
206 |
|
{ "https://www.jalview.org:443/exampl.es/uniref50", null, |
207 |
|
"https://www.jalview.org:443/exampl.es/uniref50" }, |
208 |
|
{ "https://www.jalview.org:443/examples/uniref50.", "", |
209 |
|
"https://www.jalview.org:443/examples/uniref50." }, |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
}; |
214 |
|
} |
215 |
|
} |