KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > cache > CacheKeyFactoryTest


1 /*
2  * Copyright 2005-2007 the original author or authors.
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 net.sf.dozer.util.mapping.cache;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Random JavaDoc;
21
22 import net.sf.dozer.util.mapping.DozerTestBase;
23
24 /**
25  * @author tierney.matt
26  */

27 public class CacheKeyFactoryTest extends DozerTestBase {
28
29   public void testCreateKey() throws Exception JavaDoc {
30     List JavaDoc args = new ArrayList JavaDoc();
31     args.add(String JavaDoc.class);
32     args.add(Long JavaDoc.class);
33     args.add(new String JavaDoc("hello"));
34     
35     Object JavaDoc cacheKey = CacheKeyFactory.createKey(args.toArray());
36     Object JavaDoc cacheKey2 = CacheKeyFactory.createKey(new ArrayList JavaDoc(args).toArray());
37      
38     assertEquals("cache keys should have been equal", cacheKey, cacheKey2);
39     assertEquals("cache key hash codes should have been equal", cacheKey.hashCode(), cacheKey2.hashCode());
40   }
41   
42   public void testCreateKey2() throws Exception JavaDoc {
43     String JavaDoc arg1 = "test string";
44     Long JavaDoc arg2 = new Long JavaDoc(55);
45     List JavaDoc arg3 = new ArrayList JavaDoc();
46     arg3.add("list entry");
47     Class JavaDoc arg4 = Random JavaDoc.class;
48     
49     Object JavaDoc cacheKey = CacheKeyFactory.createKey(new Object JavaDoc[] {arg1, arg2, arg3, arg4});
50     Object JavaDoc cacheKey2 = CacheKeyFactory.createKey(new Object JavaDoc[] {arg1, arg2, arg3, arg4});
51     
52     assertEquals("cache keys should have been equal", cacheKey, cacheKey2);
53     assertEquals("cache key hash codes should have been equal", cacheKey.hashCode(), cacheKey2.hashCode());
54   }
55
56 }
57
Popular Tags