]> 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
Update 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) 2007-2012 Mathieu Baudier
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 package org.argeo.slc.core.structure.tree;
17
18 import junit.framework.TestCase;
19
20 public class TreeSPathTest extends TestCase {
21
22 public void testNew() {
23 TreeSPath path = new TreeSPath("/test");
24 assertEquals("test", path.getName());
25 assertNull(path.getParent());
26
27 path = new TreeSPath("/root/subdir");
28 assertEquals("subdir", path.getName());
29 assertEquals(new TreeSPath("/root"), path.getParent());
30 }
31
32 public void testEquals() {
33 TreeSPath path1 = new TreeSPath("/test");
34 TreeSPath path2 = new TreeSPath("/test");
35 assertEquals(path1, path2);
36
37 path1 = new TreeSPath("/test/subdir/anotherdir");
38 path2 = new TreeSPath("/test/subdir/anotherdir");
39 assertEquals(path1, path2);
40
41 path1 = new TreeSPath("/test/subdir/anotherd");
42 path2 = new TreeSPath("/test/subdir/anotherdir");
43 assertNotSame(path1, path2);
44
45 path1 = new TreeSPath("/test/subdir");
46 path2 = new TreeSPath("/test/subdir/anotherdir");
47 assertNotSame(path1, path2);
48
49 path1 = new TreeSPath("/test/subd/anotherdir");
50 path2 = new TreeSPath("/test/subdir/anotherdir");
51 assertNotSame(path1, path2);
52 }
53
54 public void testCheckFormat() {
55 try {
56 new TreeSPath("hello");
57 fail("Bad format should be rejected");
58 } catch (Exception e) {
59 // exception expected
60 }
61
62 try {
63 new TreeSPath("/");
64 fail("Bad format should be rejected");
65 } catch (Exception e) {
66 // exception expected
67 }
68
69 assertEquals(new TreeSPath("/test"), new TreeSPath("/test/"));
70 assertEquals(new TreeSPath("/test/dir"), new TreeSPath(
71 "//test///dir////"));
72 }
73 }