001 package org.apache.jcs.auxiliary.disk;
002
003 import java.io.StringWriter;
004
005 import junit.framework.TestCase;
006
007 import org.apache.jcs.TestLogConfigurationUtil;
008
009 /** Unit tests for the LRUMapJCS implementation. */
010 public class LRUMapJCSUnitTest
011 extends TestCase
012 {
013 /** Verify that we default to unlimited */
014 public void testDefault()
015 {
016 // SETUP
017
018 // DO WORK
019 LRUMapJCS<String, String> map = new LRUMapJCS<String, String>();
020
021 // VERIFY
022 assertEquals( "Should be unlimted", -1, map.getMaxObjects() );
023 }
024
025 /** Verify that we default to unlimited */
026 public void testLimited()
027 {
028 // SETUP
029 int expected = 100;
030
031 // DO WORK
032 LRUMapJCS<String, String> map = new LRUMapJCS<String, String>( expected );
033
034 // VERIFY
035 assertEquals( "Should be expected", expected, map.getMaxObjects() );
036 }
037
038 /** Verify that the log message. */
039 public void testProcessRemovedLRU()
040 {
041 // SETUP
042 StringWriter stringWriter = new StringWriter();
043 TestLogConfigurationUtil.configureLogger( stringWriter, LRUMapJCS.class.getName() );
044
045 LRUMapJCS<String, String> map = new LRUMapJCS<String, String>();
046
047 String key = "myKey";
048 String value = "myValue";
049
050 // DO WORK
051 map.processRemovedLRU( key, value );
052 String result = stringWriter.toString();
053
054 // VERIFY
055 assertTrue( "Debug log should contain the key,", result.indexOf( key ) != -1 );
056 assertTrue( "Debug log should contain the value,", result.indexOf( value ) != -1 );
057 }
058 }