1   /*
2    * $Id: FilenameUtilsTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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          // make sure that we can validate the test result on all platforms.
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          // make sure that we can validate the test result on all platforms.
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       * Used to obtain base directory used in tests. Uses the build directory;
51       * "target" in the current working directory.
52       */
53      private File getBuidDirectory()
54      {
55          return FileUtils.newFile(SystemUtils.getUserDir(), "target");
56      }
57  
58  }