1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
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,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.spike;
17  
18  import java.util.Iterator;
19  
20  import org.seasar.framework.util.LruHashMap;
21  
22  import junit.framework.TestCase;
23  
24  public class LruHashMapTest extends TestCase {
25  
26  	@SuppressWarnings("unchecked")
27  	public void testA() throws Exception {
28  		LruHashMap map = new LruHashMap(3);
29  		map.put("a", "1");
30  		map.put("b", "1");
31  		map.put("c", "1");
32  		assertEquals(3, map.size());
33  		Iterator iterator = map.keySet().iterator();
34  		assertEquals("a", iterator.next());
35  		assertEquals("b", iterator.next());
36  		assertEquals("c", iterator.next());
37  		
38  		map.put("d", "1");
39  		assertEquals("最新の履歴3件のみ保持", 3, map.size());
40  		iterator = map.keySet().iterator();
41  		assertEquals("b", iterator.next());
42  		assertEquals("c", iterator.next());
43  		assertEquals("d", iterator.next());
44  		
45  		map.put("e", "1");
46  		assertEquals("最新の履歴3件のみ保持", 3, map.size());
47  		iterator = map.keySet().iterator();
48  		assertEquals("c", iterator.next());
49  		assertEquals("d", iterator.next());
50  		assertEquals("e", iterator.next());
51  	}
52  
53  }