01: package org.apache.velocity.test;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: * Checks that the equals method works correctly when caching method keys.
29: *
30: * @author <a href="Will Glass-Husain">wglass@forio.com</a>
31: * @version $Id: MethodCacheKeyTestCase.java 463298 2006-10-12 16:10:32Z henning $
32: */
33: public class MethodCacheKeyTestCase extends TestCase {
34:
35: public void testMethodKeyCacheEquals() {
36: Class[] elements1 = new Class[] { Object.class };
37: ASTMethod.MethodCacheKey mck1 = new ASTMethod.MethodCacheKey(
38: "test", elements1);
39:
40: selfEqualsAssertions(mck1);
41:
42: Class[] elements2 = new Class[] { Object.class };
43: ASTMethod.MethodCacheKey mck2 = new ASTMethod.MethodCacheKey(
44: "test", elements2);
45:
46: assertTrue(mck1.equals(mck2));
47:
48: Class[] elements3 = new Class[] { String.class };
49: ASTMethod.MethodCacheKey mck3 = new ASTMethod.MethodCacheKey(
50: "test", elements3);
51:
52: assertFalse(mck1.equals(mck3));
53:
54: Class[] elements4 = new Class[] { Object.class };
55: ASTMethod.MethodCacheKey mck4 = new ASTMethod.MethodCacheKey(
56: "boo", elements4);
57:
58: assertFalse(mck1.equals(mck4));
59:
60: /** check for potential NPE's **/
61: Class[] elements5 = ArrayUtils.EMPTY_CLASS_ARRAY;
62: ASTMethod.MethodCacheKey mck5 = new ASTMethod.MethodCacheKey(
63: "boo", elements5);
64: selfEqualsAssertions(mck5);
65:
66: Class[] elements6 = null;
67: ASTMethod.MethodCacheKey mck6 = new ASTMethod.MethodCacheKey(
68: "boo", elements6);
69: selfEqualsAssertions(mck6);
70:
71: Class[] elements7 = new Class[] {};
72: ASTMethod.MethodCacheKey mck7 = new ASTMethod.MethodCacheKey(
73: "boo", elements7);
74: selfEqualsAssertions(mck7);
75:
76: Class[] elements8 = new Class[] { null };
77: ASTMethod.MethodCacheKey mck8 = new ASTMethod.MethodCacheKey(
78: "boo", elements8);
79: selfEqualsAssertions(mck8);
80:
81: Class[] elements9 = new Class[] { Object.class };
82: ASTMethod.MethodCacheKey mck9 = new ASTMethod.MethodCacheKey(
83: "boo", elements9);
84: selfEqualsAssertions(mck9);
85:
86: }
87:
88: private void selfEqualsAssertions(ASTMethod.MethodCacheKey mck) {
89: assertTrue(mck.equals(mck));
90: assertTrue(!mck.equals(null));
91: assertTrue(!mck.equals((ASTMethod.MethodCacheKey) null));
92: }
93:
94: }
|