• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.apache.velocity.test;
2 
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "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 import org.apache.commons.lang3.ArrayUtils;
24 import org.apache.velocity.runtime.parser.node.ASTMethod;
25 
26 /**
27  * Checks that the equals method works correctly when caching method keys.
28  *
29  * @author <a href="Will Glass-Husain">wglass@forio.com</a>
30  * @version $Id$
31  */
32 public class MethodCacheKeyTestCase extends TestCase
33 {
34 
testMethodKeyCacheEquals()35     public void testMethodKeyCacheEquals()
36     {
37         Class [] elements1 = new Class [] { Object.class };
38         ASTMethod.MethodCacheKey mck1 = new ASTMethod.MethodCacheKey("test",elements1, false);
39 
40         selfEqualsAssertions(mck1);
41 
42         Class [] elements2 = new Class [] { Object.class };
43         ASTMethod.MethodCacheKey mck2 = new ASTMethod.MethodCacheKey("test",elements2, false);
44 
45         assertTrue(mck1.equals(mck2));
46 
47         Class [] elements3 = new Class [] { String.class };
48         ASTMethod.MethodCacheKey mck3 = new ASTMethod.MethodCacheKey("test",elements3, false);
49 
50         assertFalse(mck1.equals(mck3));
51 
52         Class [] elements4 = new Class [] { Object.class };
53         ASTMethod.MethodCacheKey mck4 = new ASTMethod.MethodCacheKey("boo",elements4, false);
54 
55         assertFalse(mck1.equals(mck4));
56 
57         /* check for potential NPE's */
58         Class [] elements5 = ArrayUtils.EMPTY_CLASS_ARRAY;
59         ASTMethod.MethodCacheKey mck5 = new ASTMethod.MethodCacheKey("boo",elements5, false);
60         selfEqualsAssertions(mck5);
61 
62         Class [] elements6 = null;
63         ASTMethod.MethodCacheKey mck6 = new ASTMethod.MethodCacheKey("boo",elements6, false);
64         selfEqualsAssertions(mck6);
65 
66         Class [] elements7 = new Class [] {};
67         ASTMethod.MethodCacheKey mck7 = new ASTMethod.MethodCacheKey("boo",elements7, false);
68         selfEqualsAssertions(mck7);
69 
70         Class [] elements8 = new Class [] {null};
71         ASTMethod.MethodCacheKey mck8 = new ASTMethod.MethodCacheKey("boo",elements8, false);
72         selfEqualsAssertions(mck8);
73 
74         Class [] elements9 = new Class [] { Object.class };
75         ASTMethod.MethodCacheKey mck9 = new ASTMethod.MethodCacheKey("boo",elements9, false);
76         selfEqualsAssertions(mck9);
77 
78     }
79 
selfEqualsAssertions(ASTMethod.MethodCacheKey mck)80     private void selfEqualsAssertions(ASTMethod.MethodCacheKey mck)
81     {
82         assertTrue(mck.equals(mck));
83         assertTrue(!mck.equals(null));
84         assertTrue(!mck.equals(null));
85     }
86 
87 
88 }
89