1 16 17 package org.springframework.util; 18 19 import junit.framework.TestCase; 20 21 24 public class CachingMapDecoratorTests extends TestCase { 25 26 public void testValidCache() { 27 MyCachingMap cache = new MyCachingMap(); 28 Object value; 29 30 value = cache.get("value key"); 31 assertTrue(cache.createCalled()); 32 assertEquals(value, "expensive value to cache"); 33 34 cache.get("value key 2"); 35 assertTrue(cache.createCalled()); 36 37 value = cache.get("value key"); 38 assertEquals(cache.createCalled(), false); 39 assertEquals(value, "expensive value to cache"); 40 41 cache.get("value key 2"); 42 assertEquals(cache.createCalled(), false); 43 assertEquals(value, "expensive value to cache"); 44 } 45 46 47 private static class MyCachingMap extends CachingMapDecorator { 48 49 private boolean createCalled; 50 51 protected Object create(Object key) { 52 createCalled = true; 53 return "expensive value to cache"; 54 } 55 56 public boolean createCalled() { 57 boolean c = createCalled; 58 this.createCalled = false; 59 return c; 60 } 61 } 62 63 } 64 | Popular Tags |