1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.grinder.engine.common;
23
24 import java.io.File;
25
26 import net.grinder.testutility.AbstractFileTestCase;
27 import net.grinder.testutility.Serializer;
28 import net.grinder.util.Directory;
29
30
31
32
33
34
35
36 public class TestScriptLocation extends AbstractFileTestCase {
37
38 public void testScriptLocation() throws Exception {
39
40 final Directory directory = new Directory(new File("abc"));
41 final File file1 = new File("def");
42 final File file2 = new File("blah");
43 final File file3 = new File("lah/dah");
44
45 final ScriptLocation sl1 = new ScriptLocation(directory, file1);
46 final ScriptLocation sl2 = new ScriptLocation(directory, file1);
47 final ScriptLocation sl3 = new ScriptLocation(directory, file2);
48
49 assertEquals(sl1, sl1);
50 assertEquals(sl1, sl2);
51 assertTrue(!sl1.equals(sl3));
52 assertTrue(!sl1.equals(this));
53 assertEquals(sl1.hashCode(), sl2.hashCode());
54 assertTrue(sl1.hashCode() != sl3.hashCode());
55
56 final ScriptLocation sl4 = Serializer.serialize(sl1);
57 assertEquals(sl1, sl4);
58
59 final ScriptLocation sl5 = new ScriptLocation(file1);
60 assertEquals(new File("."),
61 sl5.getDirectory().getFile());
62 assertEquals(new File(".", file1.getPath()), sl5.getFile());
63
64 final ScriptLocation sl6 = new ScriptLocation(file3);
65 assertEquals(new File("."),
66 sl6.getDirectory().getFile());
67 assertEquals(new File(".", file3.getPath()), sl6.getFile());
68 }
69
70 public void testNameShortening() throws Exception {
71 final Directory directory = new Directory(getDirectory());
72 final File existentFile = new File(getDirectory(), "hello");
73 assertTrue(existentFile.createNewFile());
74 final File nonExistentFile = new File(getDirectory(), "world");
75
76 final ScriptLocation s1 = new ScriptLocation(directory, existentFile);
77 assertEquals("hello", s1.toString());
78
79 final ScriptLocation s2 = new ScriptLocation(directory, nonExistentFile);
80 assertEquals("world", s2.toString());
81 }
82 }