diff options
Diffstat (limited to 'guava-tests/test/com/google/common/cache/LocalLoadingCacheTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/cache/LocalLoadingCacheTest.java | 63 |
1 files changed, 18 insertions, 45 deletions
diff --git a/guava-tests/test/com/google/common/cache/LocalLoadingCacheTest.java b/guava-tests/test/com/google/common/cache/LocalLoadingCacheTest.java index 90f6efb..c590cd7 100644 --- a/guava-tests/test/com/google/common/cache/LocalLoadingCacheTest.java +++ b/guava-tests/test/com/google/common/cache/LocalLoadingCacheTest.java @@ -19,19 +19,23 @@ package com.google.common.cache; import static com.google.common.cache.CacheBuilder.EMPTY_STATS; import static com.google.common.cache.LocalCacheTest.SMALL_MAX_SIZE; import static com.google.common.cache.TestingCacheLoaders.identityLoader; -import static org.truth0.Truth.ASSERT; +import static org.junit.contrib.truth.Truth.ASSERT; import com.google.common.cache.LocalCache.LocalLoadingCache; import com.google.common.cache.LocalCache.Segment; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; import com.google.common.testing.NullPointerTester; +import com.google.common.util.concurrent.Callables; import junit.framework.TestCase; import java.lang.Thread.UncaughtExceptionHandler; +import java.util.Collection; import java.util.Map; import java.util.Set; +import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -48,7 +52,7 @@ public class LocalLoadingCacheTest extends TestCase { } private CacheBuilder<Object, Object> createCacheBuilder() { - return CacheBuilder.newBuilder().recordStats(); + return new CacheBuilder<Object, Object>(); } // constructor tests @@ -68,6 +72,7 @@ public class LocalLoadingCacheTest extends TestCase { public void testNullParameters() throws Exception { NullPointerTester tester = new NullPointerTester(); + tester.setDefault(Callable.class, Callables.returning(null)); CacheLoader<Object, Object> loader = identityLoader(); tester.testAllPublicInstanceMethods(makeCache(createCacheBuilder(), loader)); } @@ -160,27 +165,24 @@ public class LocalLoadingCacheTest extends TestCase { assertNull(map.put(three, one)); assertNull(map.put(one, two)); - ASSERT.that(map).hasKey(three).withValue(one); - ASSERT.that(map).hasKey(one).withValue(two); - - //TODO(user): Confirm with fry@ that this is a reasonable substitute. - //Set<Map.Entry<Object, Object>> entries = map.entrySet(); - //ASSERT.that(entries).has().allOf( - // Maps.immutableEntry(three, one), Maps.immutableEntry(one, two)); - //Set<Object> keys = map.keySet(); - //ASSERT.that(keys).has().allOf(one, three); - //Collection<Object> values = map.values(); - //ASSERT.that(values).has().allOf(one, two); + Set<Map.Entry<Object, Object>> entries = map.entrySet(); + ASSERT.that(entries).hasContentsAnyOrder( + Maps.immutableEntry(three, one), Maps.immutableEntry(one, two)); + Set<Object> keys = map.keySet(); + ASSERT.that(keys).hasContentsAnyOrder(one, three); + Collection<Object> values = map.values(); + ASSERT.that(values).hasContentsAnyOrder(one, two); map.clear(); assertEquals(EMPTY_STATS, cache.stats()); } - public void testNoStats() { - CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder() + public void testDisableStats() { + CacheBuilder<Object, Object> builder = createCacheBuilder() .concurrencyLevel(1) - .maximumSize(2); + .maximumSize(2) + .disableStats(); LocalLoadingCache<Object, Object> cache = makeCache(builder, identityLoader()); assertEquals(EMPTY_STATS, cache.stats()); @@ -200,35 +202,6 @@ public class LocalLoadingCacheTest extends TestCase { assertEquals(EMPTY_STATS, cache.stats()); } - public void testRecordStats() { - CacheBuilder<Object, Object> builder = createCacheBuilder() - .recordStats() - .concurrencyLevel(1) - .maximumSize(2); - LocalLoadingCache<Object, Object> cache = makeCache(builder, identityLoader()); - assertEquals(0, cache.stats().hitCount()); - assertEquals(0, cache.stats().missCount()); - - Object one = new Object(); - cache.getUnchecked(one); - assertEquals(0, cache.stats().hitCount()); - assertEquals(1, cache.stats().missCount()); - - cache.getUnchecked(one); - assertEquals(1, cache.stats().hitCount()); - assertEquals(1, cache.stats().missCount()); - - Object two = new Object(); - cache.getUnchecked(two); - assertEquals(1, cache.stats().hitCount()); - assertEquals(2, cache.stats().missCount()); - - Object three = new Object(); - cache.getUnchecked(three); - assertEquals(1, cache.stats().hitCount()); - assertEquals(3, cache.stats().missCount()); - } - // asMap tests public void testAsMap() { |