1
2
3
4
5
6
7
8
9
10
11 package org.mule.util;
12
13 import java.io.File;
14
15 import junit.framework.TestCase;
16
17 public class FilenameUtilsTestCase extends TestCase
18 {
19 public void testFileWithPathComponentsNullParameter()
20 {
21 File result = FilenameUtils.fileWithPathComponents(null);
22 assertNull(result);
23 }
24
25 public void testFileWithNullElements()
26 {
27 File tempDir = getBuidDirectory();
28 File result = FilenameUtils.fileWithPathComponents(
29 new String[] {tempDir.getAbsolutePath(), "tmp", null, "bar"});
30
31
32 String resultNormalized = result.getAbsolutePath().replace(File.separatorChar, '|');
33 String excpected = tempDir.getAbsolutePath().replace(File.separatorChar, '|') + "|tmp|bar";
34 assertEquals(excpected, resultNormalized);
35 }
36
37 public void testFileWithPathComponents()
38 {
39 String tempDirPath = getBuidDirectory().getAbsolutePath();
40
41 File result = FilenameUtils.fileWithPathComponents(new String[]{tempDirPath, "tmp", "foo", "bar"});
42
43
44 String resultNormalized = result.getAbsolutePath().replace(File.separatorChar, '|');
45 String expected = tempDirPath.replace(File.separatorChar, '|') + "|tmp|foo|bar";
46 assertEquals(expected, resultNormalized);
47 }
48
49
50
51
52
53 private File getBuidDirectory()
54 {
55 return FileUtils.newFile(SystemUtils.getUserDir(), "target");
56 }
57
58 }