01: package de.schlund.pfixxml.util;
02:
03: import java.io.*;
04: import junit.framework.TestCase;
05:
06: @SuppressWarnings("deprecation")
07: public class PathTest extends TestCase {
08: private Path path;
09:
10: public void testNameOnly() {
11: path = Path.create("foo.bar");
12: assertEquals(Path.HERE, path.getBase());
13: assertEquals("foo.bar", path.getRelative());
14: }
15:
16: public void testNormal() {
17: path = Path.create(Path.HERE, "foo/bar.tgz");
18: assertEquals(new File(Path.HERE, "foo/bar.tgz"), path.resolve());
19: }
20:
21: public void testAbsolute() {
22: path = Path.create(new File("/"), "foo");
23: assertEquals(new File("/foo"), path.resolve());
24: }
25:
26: public void testEmptyRelative() {
27: path = Path.create(Path.HERE, "");
28: assertEquals("", path.getRelative());
29: assertEquals(Path.HERE, path.resolve());
30: }
31:
32: public void testRoot() {
33: assertEquals("", Path.ROOT.getName());
34: path = Path.create("");
35: assertEquals(Path.ROOT, new File("/"));
36: assertEquals("", path.getRelative());
37: }
38:
39: public void testAbsoluteBase() throws IOException {
40: System.out.println(Path.HERE.getAbsolutePath());
41: assertEquals(Path.HERE, new File(".").getCanonicalFile());
42: }
43:
44: //--
45:
46: public void testGetName() {
47: assertEquals("foo.tgz", Path.create("foo.tgz").getName());
48: assertEquals("", Path.create("").getName());
49: }
50:
51: public void testGetSuffix() {
52: assertEquals(".tgz", Path.create("foo.tgz").getSuffix());
53: assertEquals("", Path.create("foo").getSuffix());
54: assertEquals("", Path.create("").getSuffix());
55: }
56:
57: public void testGetDir() {
58: assertEquals("baz", Path
59: .create(new File("/bar"), "baz/foo.tgz").getDir());
60: assertNull(Path.create("foo").getDir());
61: assertNull(Path.create("").getDir());
62: }
63: }
|