KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > io > path > PathTest


1 package com.thoughtworks.xstream.io.path;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6
7 public class PathTest {
8
9     public static Test suite() {
10         TestSuite result = new TestSuite("PathTest");
11
12         addTest(result,
13                 "/a/b/c",
14                 "/a/b/c",
15                 ".");
16
17         addTest(result,
18                 "/a",
19                 "/a/b/c",
20                 "b/c");
21
22         addTest(result,
23                 "/a/b/c",
24                 "/a",
25                 "../..");
26
27         addTest(result,
28                 "/a/b/c",
29                 "/a/b/X",
30                 "../X");
31
32         addTest(result,
33                 "/a/b/c",
34                 "/a/X/c",
35                 "../../X/c");
36
37         addTest(result,
38                 "/a/b/c/d",
39                 "/a/X/c",
40                 "../../../X/c");
41
42         addTest(result,
43                 "/a/b/c",
44                 "/a/X/c/d",
45                 "../../X/c/d");
46
47         addTest(result,
48                 "/a/b/c[2]",
49                 "/a/b/c[3]",
50                 "../c[3]");
51
52         return result;
53     }
54
55     private static void addTest(TestSuite suite, final String JavaDoc from, final String JavaDoc to, final String JavaDoc relative) {
56         String JavaDoc testName = from + " - " + to;
57         suite.addTest(new TestCase(testName) {
58             protected void runTest() throws Throwable JavaDoc {
59                 assertEquals(new Path(relative), new Path(from).relativeTo(new Path(to)));
60                 assertEquals(new Path(to), new Path(from).apply(new Path(relative)));
61             }
62         });
63     }
64
65
66 }
67
Popular Tags