1 package org.apache.velocity.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import org.apache.commons.lang.ArrayUtils;
25 import org.apache.velocity.runtime.parser.node.ASTMethod;
26
27
28
29
30
31
32
33 public class MethodCacheKeyTestCase extends TestCase
34 {
35
36 public void testMethodKeyCacheEquals()
37 {
38 Class [] elements1 = new Class [] { Object.class };
39 ASTMethod.MethodCacheKey mck1 = new ASTMethod.MethodCacheKey("test",elements1);
40
41 selfEqualsAssertions(mck1);
42
43 Class [] elements2 = new Class [] { Object.class };
44 ASTMethod.MethodCacheKey mck2 = new ASTMethod.MethodCacheKey("test",elements2);
45
46 assertTrue(mck1.equals(mck2));
47
48 Class [] elements3 = new Class [] { String.class };
49 ASTMethod.MethodCacheKey mck3 = new ASTMethod.MethodCacheKey("test",elements3);
50
51 assertFalse(mck1.equals(mck3));
52
53 Class [] elements4 = new Class [] { Object.class };
54 ASTMethod.MethodCacheKey mck4 = new ASTMethod.MethodCacheKey("boo",elements4);
55
56 assertFalse(mck1.equals(mck4));
57
58
59 Class [] elements5 = ArrayUtils.EMPTY_CLASS_ARRAY;
60 ASTMethod.MethodCacheKey mck5 = new ASTMethod.MethodCacheKey("boo",elements5);
61 selfEqualsAssertions(mck5);
62
63 Class [] elements6 = null;
64 ASTMethod.MethodCacheKey mck6 = new ASTMethod.MethodCacheKey("boo",elements6);
65 selfEqualsAssertions(mck6);
66
67 Class [] elements7 = new Class [] {};
68 ASTMethod.MethodCacheKey mck7 = new ASTMethod.MethodCacheKey("boo",elements7);
69 selfEqualsAssertions(mck7);
70
71 Class [] elements8 = new Class [] {null};
72 ASTMethod.MethodCacheKey mck8 = new ASTMethod.MethodCacheKey("boo",elements8);
73 selfEqualsAssertions(mck8);
74
75 Class [] elements9 = new Class [] { Object.class };
76 ASTMethod.MethodCacheKey mck9 = new ASTMethod.MethodCacheKey("boo",elements9);
77 selfEqualsAssertions(mck9);
78
79 }
80
81 private void selfEqualsAssertions(ASTMethod.MethodCacheKey mck)
82 {
83 assertTrue(mck.equals(mck));
84 assertTrue(!mck.equals(null));
85 assertTrue(!mck.equals((ASTMethod.MethodCacheKey) null));
86 }
87
88
89 }