1 package org.apache.maven.plugin.reactor;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.maven.plugin.reactor.RelativePather.DifferentRootsException;
25
26 import junit.framework.TestCase;
27
28 public class RelativePatherTest extends TestCase {
29 File root;
30 File differentRoot;
31 char S = File.separatorChar;
32
33 public void setUp() {
34 File[] roots = File.listRoots();
35 root = roots[0];
36 if (roots.length > 1) {
37 differentRoot = roots[1];
38 }
39 }
40
41 public void testIdenticalRoots() {
42 assertEquals("", getRelativePath(root, root));
43 }
44
45 public void testDifferentRoots() {
46
47 if (differentRoot == null) return;
48 try {
49 getRelativePath(root, differentRoot);
50 fail("Expected different roots exception");
51 } catch (DifferentRootsException e) {}
52 }
53
54 public void testIdenticalFoo() {
55 File foo = new File(root, "foo");
56 assertEquals("", getRelativePath(foo, foo));
57 }
58
59 public void testIdenticalFooFoo() {
60 File foo = new File(root, "foo/foo");
61 assertEquals("", getRelativePath(foo, foo));
62 }
63
64 public void testFooBar() {
65 File foo = new File(root, "foo");
66 File bar = new File(root, "bar");
67 assertEquals(".." + S + "bar", getRelativePath(foo, bar));
68 }
69
70 public void testRootFoo() {
71 File foo = new File(root, "foo");
72 assertEquals("foo", getRelativePath(root, foo));
73 }
74
75 public void testFooRoot() {
76 File foo = new File(root, "foo");
77 assertEquals("..", getRelativePath(foo, root));
78 }
79
80 public void testFooFooBarBar() {
81 File foo = new File(root, "foo/foo");
82 File bar = new File(root, "bar/bar");
83 assertEquals(".." + S + ".." + S + "bar" + S + "bar", getRelativePath(foo, bar));
84 }
85
86 public String getRelativePath(File context, File dest) {
87 return RelativePather.getRelativePath(context, dest);
88 }
89 }