Lines 253-258
Link Here
|
253 |
/** Tests normalizeFile() method. */ |
253 |
/** Tests normalizeFile() method. */ |
254 |
public void testNormalizeFile() throws IOException { |
254 |
public void testNormalizeFile() throws IOException { |
255 |
// pairs of path before and after normalization |
255 |
// pairs of path before and after normalization |
|
|
256 |
Map<String, String> paths = createNormalizedPaths(); |
257 |
|
258 |
for (String path : paths.keySet()) { |
259 |
File file = new File(path); |
260 |
assertTrue("Idempotency violated for path: " + path, FileUtil.normalizeFile(FileUtil.normalizeFile(file)).equals(FileUtil.normalizeFile(file))); |
261 |
assertEquals("File not normalized: " + path, paths.get(path), FileUtil.normalizeFile(file).getPath()); |
262 |
} |
263 |
} |
264 |
|
265 |
public void testNormalizeFileIsCached() throws Exception { |
266 |
File f = new File(getWorkDir(), "text.txt"); |
267 |
CharSequence log = Log.enable(FileUtil.class.getName(), Level.FINE); |
268 |
File one = FileUtil.normalizeFile(f); |
269 |
String msg = "FileUtil.normalizeFile for " + f; |
270 |
if (log.toString().indexOf(msg) == -1) { |
271 |
fail("One querfy for the file shall be in logs:\n" + log); |
272 |
} |
273 |
CharSequence log2 = Log.enable(FileUtil.class.getName(), Level.FINE); |
274 |
File two = FileUtil.normalizeFile(f); |
275 |
if (log2.toString().contains(msg)) { |
276 |
fail("No second FileUtil.normalizeFile for in:\n" + log); |
277 |
} |
278 |
assertEquals("Files are equal", one, two); |
279 |
} |
280 |
|
281 |
/** Tests normalizePath() method. */ |
282 |
public void testNormalizePath() throws IOException { |
283 |
// pairs of path before and after normalization |
284 |
Map<String, String> paths = createNormalizedPaths(); |
285 |
|
286 |
for (String path : paths.keySet()) { |
287 |
assertTrue("Idempotency violated for path: " + path, FileUtil.normalizePath(FileUtil.normalizePath(path)).equals(FileUtil.normalizePath(path))); |
288 |
assertEquals("File path not normalized: " + path, paths.get(path), FileUtil.normalizePath(path)); |
289 |
} |
290 |
} |
291 |
|
292 |
private Map<String, String> createNormalizedPaths() throws IOException { |
293 |
// pairs of path before and after normalization |
256 |
Map<String, String> paths = new HashMap<String, String>(); |
294 |
Map<String, String> paths = new HashMap<String, String>(); |
257 |
if (Utilities.isWindows()) { |
295 |
if (Utilities.isWindows()) { |
258 |
paths.put("A:\\", "A:\\"); |
296 |
paths.put("A:\\", "A:\\"); |
Lines 291-320
Link Here
|
291 |
// #137407 - java.io.File(".") should be normalized |
329 |
// #137407 - java.io.File(".") should be normalized |
292 |
paths.put(".", new File(".").getCanonicalPath()); |
330 |
paths.put(".", new File(".").getCanonicalPath()); |
293 |
paths.put("..", new File("..").getCanonicalPath()); |
331 |
paths.put("..", new File("..").getCanonicalPath()); |
294 |
|
332 |
return paths; |
295 |
for (String path : paths.keySet()) { |
|
|
296 |
File file = new File(path); |
297 |
assertTrue("Idempotency violated for path: " + path, FileUtil.normalizeFile(FileUtil.normalizeFile(file)).equals(FileUtil.normalizeFile(file))); |
298 |
assertEquals("File not normalized: " + path, paths.get(path), FileUtil.normalizeFile(file).getPath()); |
299 |
} |
300 |
} |
333 |
} |
301 |
|
334 |
|
302 |
public void testNormalizeFileIsCached() throws Exception { |
335 |
public void testNormalizePathIsCached() throws Exception { |
303 |
File f = new File(getWorkDir(), "text.txt"); |
336 |
File f = new File(getWorkDir(), "textPath.txt"); |
|
|
337 |
String path = f.getPath(); |
304 |
CharSequence log = Log.enable(FileUtil.class.getName(), Level.FINE); |
338 |
CharSequence log = Log.enable(FileUtil.class.getName(), Level.FINE); |
305 |
File one = FileUtil.normalizeFile(f); |
339 |
String one = FileUtil.normalizePath(path); |
306 |
String msg = "FileUtil.normalizeFile for " + f; |
340 |
String msg = "FileUtil.normalizeFile for " + f; |
307 |
if (log.toString().indexOf(msg) == -1) { |
341 |
if (log.toString().indexOf(msg) == -1) { |
308 |
fail("One querfy for the file shall be in logs:\n" + log); |
342 |
fail("One querfy for the file shall be in logs:\n" + log); |
309 |
} |
343 |
} |
310 |
CharSequence log2 = Log.enable(FileUtil.class.getName(), Level.FINE); |
344 |
CharSequence log2 = Log.enable(FileUtil.class.getName(), Level.FINE); |
311 |
File two = FileUtil.normalizeFile(f); |
345 |
String two = FileUtil.normalizePath(path); |
312 |
if (log2.toString().contains(msg)) { |
346 |
if (log2.toString().contains(msg)) { |
313 |
fail("No second FileUtil.normalizeFile for in:\n" + log); |
347 |
fail("No second FileUtil.normalizeFile for in:\n" + log); |
314 |
} |
348 |
} |
315 |
assertEquals("Files are equal", one, two); |
349 |
assertEquals("Files are equal", one, two); |
316 |
} |
350 |
} |
317 |
|
|
|
318 |
|
351 |
|
319 |
/** Tests that only resolvers are queried which supply at least one of |
352 |
/** Tests that only resolvers are queried which supply at least one of |
320 |
* MIME types given in array in FileUtil.getMIMEType(fo, String[]). |
353 |
* MIME types given in array in FileUtil.getMIMEType(fo, String[]). |