1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 package net.objectlab.qalab.util;
40
41 import junit.framework.TestCase;
42
43 /**
44 * Test for Utility class for file name manipulations.
45 *
46 * @author Dave Sag
47 * @author Benoit Xhenseval
48 */
49 public class FilenameUtilTest extends TestCase {
50 /**
51 * Test trimFilename with a unix style path and relative src dir ending
52 * in a slash.
53 */
54 public void testTrimFilenameUnixPathsRelativeSrcEndsWithSlash() {
55 final String theSrcDir = "tester/src/";
56 final String theFilePath = "/Users/tester/src/main/java/com/test/SomeTest.java";
57 validate(theSrcDir, theFilePath);
58 }
59
60 /**
61 * Test trimFilename with a unix style path and relative src dir not
62 * ending in a slash.
63 */
64 public void testTrimFilenameUnixPathsRelativeSrcEndsNoSlash() {
65 final String theSrcDir = "tester/src";
66 final String theFilePath = "/Users/tester/src/main/java/com/test/SomeTest.java";
67 validate(theSrcDir, theFilePath);
68 }
69
70 /**
71 * Test trimFilename with a unix style path and src dir ending in a slash.
72 */
73 public void testTrimFilenameUnixPathsSrcEndsWithSlash() {
74 final String theSrcDir = "/Users/tester/src/";
75 final String theFilePath = "/Users/tester/src/main/java/com/test/SomeTest.java";
76 validate(theSrcDir, theFilePath);
77 }
78
79 /**
80 * Test trimFilename with a unix style path and src dir
81 * that is not ending in a slash.
82 */
83 public void testTrimFilenameUnixPathsSrcNotEndsWithSlash() {
84 final String theSrcDir = "/Users/tester/src";
85 final String theFilePath = "/Users/tester/src/main/java/com/test/SomeTest.java";
86 validate(theSrcDir, theFilePath);
87 }
88
89 /**
90 * Test trimFilename with a windows style path and src dir
91 * ending in a slash.
92 */
93 public void testTrimFilenameWindozePathsSrcEndsWithSlash() {
94 final String theSrcDir = "C:\\src\\";
95 final String theFilePath = "C:\\src\\main\\java\\com\\test\\SomeTest.java";
96 validate(theSrcDir, theFilePath);
97 }
98
99 /**
100 * Test trimFilename with a windows style path and src dir
101 * that is not ending in a slash.
102 */
103 public void testTrimFilenameWindozePathsSrcNotEndsWithSlash() {
104 final String theSrcDir = "C:\\src\\";
105 final String theFilePath = "C:\\src\\main\\java\\com\\test\\SomeTest.java";
106 validate(theSrcDir, theFilePath);
107 }
108
109 /**
110 * Test trimFilename with a path that it should leave untouched.
111 */
112 public void testTrimFilenameNoChange() {
113 final String theSrcDir = "src/main/java";
114 final String theFilePath = "com/test/SomeTest.java";
115 assertEquals("no change",theFilePath,FilenameUtil.trimFilename(theFilePath, theSrcDir));
116 }
117
118 private void validate(final String srcdir, final String file) {
119 final String expected = "main/java/com/test/SomeTest.java";
120 final String actual = FilenameUtil.trimFilename(file, srcdir);
121 assertEquals("trimmed filename was wrong.\noriginal path '"
122 + file
123 + "',\nsrc dir '"
124 + srcdir
125 + "',\nactual result '"
126 + actual + "'.",
127 expected, actual);
128 }
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145