KickJava   Java API By Example, From Geeks To Geeks.

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


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 RelativePathCalculatorTest {
8
9     public static Test suite() {
10         TestSuite result = new TestSuite("RelativePathCalculator");
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                 RelativePathCalculator calculator = new RelativePathCalculator();
60                 assertEquals(relative, calculator.relativePath(from, to));
61                 assertEquals(to, calculator.absolutePath(from, relative));
62             }
63         });
64     }
65
66
67 }
68
Popular Tags