X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fcache%2FCachedObjectTest.java;h=955a71148512c47010e4f042dc318703f6629559;hb=17775e14ecfb286e59f67117e5cee7e21e95ab1f;hp=4ed1d2d2aae32ffe965308b6c5fbb259f71d4842;hpb=ddd261f331280640c5b53c7128230b629ebcd268;p=utils diff --git a/support/general/src/test/java/org/wamblee/cache/CachedObjectTest.java b/support/general/src/test/java/org/wamblee/cache/CachedObjectTest.java index 4ed1d2d2..955a7114 100644 --- a/support/general/src/test/java/org/wamblee/cache/CachedObjectTest.java +++ b/support/general/src/test/java/org/wamblee/cache/CachedObjectTest.java @@ -1,18 +1,18 @@ /* - * Copyright 2005 the original author or authors. - * + * Copyright 2005-2010 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.cache; import junit.framework.TestCase; @@ -25,35 +25,32 @@ import org.wamblee.test.TimingUtils; import java.io.IOException; - /** * Cached object test. - * + * * @author Erik Brakkee */ public class CachedObjectTest extends TestCase { - /** - * - */ private static final String EHCACHE_CONFIG = "ehcache.xml"; private static final int OBJECT_KEY = 10; private CachedObject.Computation computation; private int ncomputations; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); computation = new CachedObject.Computation() { - public Integer getObject(Integer aObjectKey) { - ncomputations++; + public Integer getObject(Integer aObjectKey) { + ncomputations++; - return compute(aObjectKey); - } - ; - }; + return compute(aObjectKey); + }; + }; ncomputations = 0; } @@ -70,7 +67,7 @@ public class CachedObjectTest extends TestCase { /** * Verifies that upon first use, the cached object uses the computation to * retrieve the object. - * + * */ public void testComputation() { CachedObject cached = createCached(new ZeroCache()); @@ -91,8 +88,8 @@ public class CachedObjectTest extends TestCase { } public void testBehaviorEhCache() throws CacheException, IOException { - Cache cache = new EhCache(new TestResource( - CachedObjectTest.class, EHCACHE_CONFIG), "test"); + Cache cache = new EhCache( + new TestResource(CachedObjectTest.class, EHCACHE_CONFIG), "test"); CachedObject cached = createCached(cache); assertTrue(cache == cached.getCache()); @@ -100,12 +97,12 @@ public class CachedObjectTest extends TestCase { int value = cached.get(); assertEquals(compute(OBJECT_KEY), value); assertEquals(1, ncomputations); - // The value must still be cached. + // The value must still be cached. value = cached.get(); assertEquals(compute(OBJECT_KEY), value); assertEquals(1, ncomputations); - // Cache expiry. + // Cache expiry. TimingUtils.sleep(6000); value = cached.get(); assertEquals(compute(OBJECT_KEY), value); @@ -124,8 +121,9 @@ public class CachedObjectTest extends TestCase { } public void testBehaviorEhCacheDefault() throws CacheException, IOException { - Cache cache = new EhCache(new TestResource( - CachedObjectTest.class, EHCACHE_CONFIG), "undefined"); + Cache cache = new EhCache( + new TestResource(CachedObjectTest.class, EHCACHE_CONFIG), + "undefined"); CachedObject cached = createCached(cache); assertTrue(cache == cached.getCache()); @@ -133,12 +131,12 @@ public class CachedObjectTest extends TestCase { int value = cached.get(); assertEquals(compute(OBJECT_KEY), value); assertEquals(1, ncomputations); - // The value must still be cached. + // The value must still be cached. value = cached.get(); assertEquals(compute(OBJECT_KEY), value); assertEquals(1, ncomputations); - // Cache expiry. + // Cache expiry. TimingUtils.sleep(6000); value = cached.get(); assertEquals(compute(OBJECT_KEY), value);