01: /*
02: * Copyright (C) 2004 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 02. September 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.io.path;
13:
14: import junit.framework.Test;
15: import junit.framework.TestCase;
16: import junit.framework.TestSuite;
17:
18: public class PathTest {
19:
20: public static Test suite() {
21: TestSuite result = new TestSuite(PathTest.class.getName());
22:
23: addTest(result, "/a/b/c", "/a/b/c", ".", true);
24:
25: addTest(result, "/a", "/a/b/c", "b/c", true);
26:
27: addTest(result, "/a/b/c", "/a", "../..", false);
28:
29: addTest(result, "/a/b/c", "/a/b/X", "../X", false);
30:
31: addTest(result, "/a/b/c", "/a/X/c", "../../X/c", false);
32:
33: addTest(result, "/a/b/c/d", "/a/X/c", "../../../X/c", false);
34:
35: addTest(result, "/a/b/c", "/a/X/c/d", "../../X/c/d", false);
36:
37: addTest(result, "/a/b/c[2]", "/a/b/c[3]", "../c[3]", false);
38:
39: return result;
40: }
41:
42: private static void addTest(TestSuite suite, final String from,
43: final String to, final String relative,
44: final boolean isAncestor) {
45: String testName = from + " - " + to;
46: suite.addTest(new TestCase(testName) {
47: protected void runTest() throws Throwable {
48: assertEquals(new Path(relative), new Path(from)
49: .relativeTo(new Path(to)));
50: assertEquals(new Path(to), new Path(from)
51: .apply(new Path(relative)));
52: assertEquals(isAncestor, new Path(from)
53: .isAncestor(new Path(to)));
54: }
55: });
56: }
57:
58: }
|