View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
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          // make sure that we can validate the test result on all platforms.
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          // make sure that we can validate the test result on all platforms.
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       * Used to obtain base directory used in tests. Uses the build directory;
56       * "target" in the current working directory.
57       */
58      private File getBuidDirectory()
59      {
60          return FileUtils.newFile(SystemUtils.getUserDir(), "target");
61      }
62  
63  }