1
|
|
package abbot.util;
|
2
|
|
|
3
|
|
import java.io.File;
|
4
|
|
|
5
|
|
import junit.extensions.abbot.TestHelper;
|
6
|
|
import junit.framework.TestCase;
|
7
|
|
import abbot.Platform;
|
8
|
|
|
9
|
|
public class PathClassLoaderTest extends TestCase {
|
10
|
|
|
11
|
1
|
public void testConvertPathToFilesW32() {
|
12
|
1
|
if (Platform.isWindows()) {
|
13
|
1
|
String path = "c:\\;c:\\mydir;.";
|
14
|
1
|
String[] names =
|
15
|
|
PathClassLoader.convertPathToFilenames(path, ":;");
|
16
|
1
|
String[] expected = {
|
17
|
|
"c:\\", "c:\\mydir", "."
|
18
|
|
};
|
19
|
1
|
assertEquals("Wrong number of files",
|
20
|
|
expected.length, names.length);
|
21
|
1
|
for (int i=0;i < names.length;i++) {
|
22
|
3
|
assertEquals("Wrong path", expected[i], names[i]);
|
23
|
|
}
|
24
|
|
}
|
25
|
|
}
|
26
|
|
|
27
|
1
|
public void testConvertPathToFiles() {
|
28
|
|
|
29
|
1
|
String path = "/:/tmp:/tmp/mydir:.";
|
30
|
1
|
String[] names = PathClassLoader.convertPathToFilenames(path, ":;");
|
31
|
1
|
String[] expected = {
|
32
|
|
"/", "/tmp", "/tmp/mydir", "."
|
33
|
|
};
|
34
|
1
|
assertEquals("Wrong number of files",
|
35
|
|
expected.length, names.length);
|
36
|
1
|
for (int i=0;i < names.length;i++) {
|
37
|
4
|
assertEquals("Wrong path", expected[i], names[i]);
|
38
|
|
}
|
39
|
|
}
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
1
|
public void testLoadResource() throws Throwable {
|
45
|
1
|
String pathName = "lib/example.jar";
|
46
|
1
|
String rsrc = "/example/logo32.gif";
|
47
|
1
|
String sysPath = System.getProperty("java.class.path");
|
48
|
1
|
assertTrue("Can't test, path " + pathName
|
49
|
|
+ " is already in classpath " + sysPath,
|
50
|
|
sysPath.indexOf(pathName) == -1);
|
51
|
|
|
52
|
1
|
ClassLoader cl = new PathClassLoader(pathName,
|
53
|
|
getClass().getClassLoader());
|
54
|
1
|
try {
|
55
|
1
|
cl.getResourceAsStream(rsrc);
|
56
|
|
}
|
57
|
|
catch(Exception exc) {
|
58
|
0
|
fail("Resource not found: " + exc.getMessage());
|
59
|
|
}
|
60
|
|
}
|
61
|
|
|
62
|
|
|
63
|
|
|
64
|
|
|
65
|
1
|
public void testLoadClassFromPath() throws Throwable {
|
66
|
1
|
String pathName = "lib/example.jar";
|
67
|
1
|
String className = "example.FontChooser";
|
68
|
1
|
String sysPath = System.getProperty("java.class.path");
|
69
|
1
|
assertTrue("Can't test, path " + pathName
|
70
|
|
+ " is already in classpath " + sysPath,
|
71
|
|
sysPath.indexOf(pathName) == -1);
|
72
|
1
|
ClassLoader cl = new PathClassLoader(pathName,
|
73
|
|
getClass().getClassLoader());
|
74
|
1
|
try {
|
75
|
1
|
Class.forName(className, true, cl);
|
76
|
|
}
|
77
|
|
catch(ClassNotFoundException cnf) {
|
78
|
0
|
fail("Path class loader failed to load " + className
|
79
|
|
+ " from path " + pathName);
|
80
|
|
}
|
81
|
|
}
|
82
|
|
|
83
|
4
|
public PathClassLoaderTest(String name) {
|
84
|
4
|
super(name);
|
85
|
|
}
|
86
|
|
|
87
|
0
|
public static void main(String[] args) {
|
88
|
0
|
TestHelper.runTests(args, PathClassLoaderTest.class);
|
89
|
|
}
|
90
|
|
}
|
91
|
|
|