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