01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.util;
04:
05: import junit.framework.*;
06: import java.io.File;
07: import java.util.*;
08:
09: public class WildcardTest extends TestCase {
10: private File testDir;
11:
12: public void setUp() throws Exception {
13: makeSampleFiles();
14: testDir = new File("testDir");
15: }
16:
17: public void tearDown() throws Exception {
18: deleteSampleFiles();
19: }
20:
21: public void testJar() throws Exception {
22: Wildcard wildcard = new Wildcard("*.jar");
23: File[] files = testDir.listFiles(wildcard);
24: List list = fileArrayToStringList(files);
25: assertEquals(2, files.length);
26: assertTrue(list.contains("one.jar"));
27: assertTrue(list.contains("two.jar"));
28: }
29:
30: public void testDll() throws Exception {
31: Wildcard wildcard = new Wildcard("*.dll");
32: File[] files = testDir.listFiles(wildcard);
33: List list = fileArrayToStringList(files);
34: assertEquals(2, files.length);
35: assertTrue(list.contains("one.dll"));
36: assertTrue(list.contains("two.dll"));
37: }
38:
39: public void testOne() throws Exception {
40: Wildcard wildcard = new Wildcard("one*");
41: File[] files = testDir.listFiles(wildcard);
42: List list = fileArrayToStringList(files);
43: assertEquals(3, files.length);
44: assertTrue(list.contains("oneA"));
45: assertTrue(list.contains("one.jar"));
46: assertTrue(list.contains("one.dll"));
47: }
48:
49: public void testAll() throws Exception {
50: Wildcard wildcard = new Wildcard("*");
51: File[] files = testDir.listFiles(wildcard);
52: assertEquals(6, files.length);
53: }
54:
55: private List fileArrayToStringList(File[] files) {
56: List list = new ArrayList();
57: for (int i = 0; i < files.length; i++) {
58: File file = files[i];
59: list.add(file.getName());
60: }
61: return list;
62: }
63:
64: public static void makeSampleFiles() {
65: FileUtil.makeDir("testDir");
66: FileUtil.createFile("testDir/one.jar", "");
67: FileUtil.createFile("testDir/two.jar", "");
68: FileUtil.createFile("testDir/one.dll", "");
69: FileUtil.createFile("testDir/two.dll", "");
70: FileUtil.createFile("testDir/oneA", "");
71: FileUtil.createFile("testDir/twoA", "");
72: }
73:
74: public static void deleteSampleFiles() {
75: FileUtil.deleteFileSystemDirectory("testDir");
76: }
77:
78: }
|