@@ -0,0 +1,2151 @@
+package xdean.jex.util.cache;%0D%0A%0D%0Aimport static org.junit.Assert.*;%0D%0Aimport static xdean.jex.util.cache.CacheUtil.*;%0D%0A%0D%0Aimport java.util.concurrent.atomic.AtomicInteger;%0D%0A%0D%0Aimport org.junit.Test;%0D%0A%0D%0Aimport xdean.jex.extra.Wrapper;%0D%0Aimport xdean.jex.util.reflect.ReflectUtil;%0D%0A%0D%0Apublic class CacheUtilTest %7B%0D%0A  @Test%0D%0A  public void testGetSet() throws Exception %7B%0D%0A    set(key(), 123);%0D%0A    assertEquals(123, get(key()).get());%0D%0A  %7D%0D%0A%0D%0A  @Test%0D%0A  public void testCache() throws Exception %7B%0D%0A    AtomicInteger call = new AtomicInteger(0);%0D%0A    Object key = key();%0D%0A    cache(key, () -%3E call.incrementAndGet());%0D%0A    cache(key, () -%3E call.incrementAndGet());%0D%0A    cache(key, () -%3E call.incrementAndGet());%0D%0A    assertEquals(1, call.get());%0D%0A  %7D%0D%0A%0D%0A  @Test%0D%0A  public void testCacheGC() throws Exception %7B%0D%0A    AtomicInteger call = new AtomicInteger(0);%0D%0A    cache(key(), () -%3E call.incrementAndGet());%0D%0A    System.gc();%0D%0A    cache(key(), () -%3E call.incrementAndGet());%0D%0A    cache(key(), () -%3E call.incrementAndGet());%0D%0A    System.gc();%0D%0A    cache(key(), () -%3E call.incrementAndGet());%0D%0A    assertEquals(3, call.get());%0D%0A  %7D%0D%0A%0D%0A  @Test%0D%0A  public void testCacheWeak() throws Exception %7B%0D%0A    AtomicInteger call = new AtomicInteger(0);%0D%0A    Object key = key();%0D%0A    cacheWeak(key, () -%3E call.incrementAndGet());%0D%0A    cacheWeak(key, () -%3E call.incrementAndGet());%0D%0A    cacheWeak(key, () -%3E call.incrementAndGet());%0D%0A    assertEquals(1, call.get());%0D%0A  %7D%0D%0A%0D%0A  @Test%0D%0A  public void testCacheWeakGC() throws Exception %7B%0D%0A    AtomicInteger call = new AtomicInteger(1000);%0D%0A    Object k = key();%0D%0A    cacheWeak(k, () -%3E call.incrementAndGet());%0D%0A    System.gc();%0D%0A    cacheWeak(k, () -%3E call.incrementAndGet());%0D%0A    cacheWeak(k, () -%3E call.incrementAndGet());%0D%0A    System.gc();%0D%0A    cacheWeak(k, () -%3E call.incrementAndGet());%0D%0A    assertEquals(1003, call.get());%0D%0A  %7D%0D%0A%0D%0A  @Test%0D%0A  public void testRemove() throws Exception %7B%0D%0A    set(key(), 123);%0D%0A    assertEquals(123, remove(key()).get());%0D%0A    assertFalse(remove(new Object()).isPresent());%0D%0A  %7D%0D%0A%0D%0A  private Object key() %7B%0D%0A    return new Wrapper%3C%3E(ReflectUtil.getCaller(1, false).getMethodName());%0D%0A  %7D%0D%0A%7D%0D%0A

add test