001/**
002 * Copyright 2010 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015
016package org.kuali.student.common.util;
017
018import junit.framework.Assert;
019
020import org.junit.Before;
021import org.junit.Test;
022
023public class TestLRUMap {
024
025        private LRUMap<String,String> cache;
026
027        @Before
028        public void setup() {
029                cache = new LRUMap<String,String>(3);
030                cache.put("key-1", "value-1");
031                cache.put("key-2", "value-2");
032                cache.put("key-3", "value-3");
033        }
034        
035        @Test
036        public void testDefaultMaximumEntries() throws Exception {
037                cache = new LRUMap<String,String>();
038                for(int i=0; i<60; i++) {
039                        cache.put("key-"+i, "value-"+i);
040                }
041                Assert.assertEquals(50, cache.size());
042        }
043
044        @Test
045        public void testRemoveEldestEntry() throws Exception {
046                cache.put("key-4", "value-4");
047                Assert.assertEquals(3, cache.size());
048                Assert.assertNull(cache.get("key-1"));
049        }
050        
051}