View Javadoc

1   package com.melloware.jukes.file;
2   
3   import java.io.File;
4   import java.io.IOException;
5   
6   import org.apache.commons.io.FileUtils;
7   
8   import com.melloware.jukes.AbstractTestCase;
9   
10  /**
11   * Test case to test out the FileUtil class.
12   * <p>
13   * Copyright (c) 2006
14   * Melloware, Inc. <http://www.melloware.com>
15   * @author Emil A. Lefkof III <info@melloware.com>
16   * @version 4.0
17   */
18  public class FileUtilTest
19      extends AbstractTestCase {
20  
21      /**
22       * Constructor for FileUtilTest.
23       * @param arg0
24       */
25      public FileUtilTest(String arg0) {
26          super(arg0);
27      }
28  
29      public static void main(String[] args) {
30          junit.textui.TestRunner.run(FileUtilTest.class);
31      }
32  
33      /*
34       * Test method for 'com.melloware.jukes.file.FileUtil.setReadOnly(File, boolean)'
35       */
36      public void testSetReadOnly() {
37          File file = null;
38          try {
39              file = File.createTempFile("test", ".tmp");
40  
41              // try setting readonly
42              FileUtil.setReadOnly(file, true);
43              FileUtil.setReadOnly(file, false);
44  
45              FileUtils.forceDelete(file);
46  
47          } catch (IOException ex) {
48              fail("IOException testing readonly" + ex.getMessage());
49          }
50  
51      }
52      
53      /*
54       * Test method for 'com.melloware.jukes.file.FileUtil.capitalize(string)'
55       */
56      public void testCapitalize() {
57         String test1 = "tESt 1";
58         String test2 = "Test two";
59         String test3 = "Test 3" ;
60         
61         assertEquals(FileUtil.capitalize(test1), "Test 1");
62         assertEquals(FileUtil.capitalize(test2), "Test Two");
63         assertEquals(FileUtil.capitalize(test3), "Test 3");
64      }
65      
66      /*
67       * Test method for 'com.melloware.jukes.file.FileUtil.corectFilename(string)'
68       */
69      public void testCorrectFilename() {
70         String test1 = "Test*1.mp3";
71         String test2 = "Te?st2.mp3";
72         String test3 = "<Test> 3:.mp3" ;
73         
74         assertEquals(FileUtil.correctFileName(test1), "Test_1.mp3");
75         assertEquals(FileUtil.correctFileName(test2), "Te_st2.mp3");
76         assertEquals(FileUtil.correctFileName(test3), "_Test_ 3_.mp3");
77      }
78  
79  
80      /*
81       * @see TestCase#setUp()
82       */
83      protected void setUp()
84                    throws Exception {
85          super.setUp();
86      }
87  
88      /*
89       * @see TestCase#tearDown()
90       */
91      protected void tearDown()
92                       throws Exception {
93          super.tearDown();
94      }
95  
96  }