]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/test/java/org/argeo/slc/core/structure/tree/TreeSPathTest.java
Add license headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / test / java / org / argeo / slc / core / structure / tree / TreeSPathTest.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.structure.tree;
18
19 import junit.framework.TestCase;
20
21 public class TreeSPathTest extends TestCase {
22
23 public void testNew() {
24 TreeSPath path = new TreeSPath("/test");
25 assertEquals("test", path.getName());
26 assertNull(path.getParent());
27
28 path = new TreeSPath("/root/subdir");
29 assertEquals("subdir", path.getName());
30 assertEquals(new TreeSPath("/root"), path.getParent());
31 }
32
33 public void testEquals() {
34 TreeSPath path1 = new TreeSPath("/test");
35 TreeSPath path2 = new TreeSPath("/test");
36 assertEquals(path1, path2);
37
38 path1 = new TreeSPath("/test/subdir/anotherdir");
39 path2 = new TreeSPath("/test/subdir/anotherdir");
40 assertEquals(path1, path2);
41
42 path1 = new TreeSPath("/test/subdir/anotherd");
43 path2 = new TreeSPath("/test/subdir/anotherdir");
44 assertNotSame(path1, path2);
45
46 path1 = new TreeSPath("/test/subdir");
47 path2 = new TreeSPath("/test/subdir/anotherdir");
48 assertNotSame(path1, path2);
49
50 path1 = new TreeSPath("/test/subd/anotherdir");
51 path2 = new TreeSPath("/test/subdir/anotherdir");
52 assertNotSame(path1, path2);
53 }
54
55 public void testCheckFormat() {
56 try {
57 new TreeSPath("hello");
58 fail("Bad format should be rejected");
59 } catch (Exception e) {
60 // exception expected
61 }
62
63 try {
64 new TreeSPath("/");
65 fail("Bad format should be rejected");
66 } catch (Exception e) {
67 // exception expected
68 }
69
70 assertEquals(new TreeSPath("/test"), new TreeSPath("/test/"));
71 assertEquals(new TreeSPath("/test/dir"), new TreeSPath(
72 "//test///dir////"));
73 }
74 }