Ejemplo n.º 1
0
 @Test
 public void test1() {
   final FIFOCache<Integer, Integer> cache = new FIFOCache<Integer, Integer>(1);
   Assert.assertEquals(0, cache.size());
   cache.put(1, 1);
   Assert.assertEquals(1, cache.size());
   cache.put(2, 2);
   Assert.assertEquals(1, cache.size());
   Assert.assertEquals(2, cache.keySet().iterator().next().intValue());
 }
Ejemplo n.º 2
0
 @Test
 public void test2() {
   final FIFOCache<Integer, Integer> cache = new FIFOCache<Integer, Integer>(500);
   int expectedCacheSize = 0;
   Assert.assertEquals(expectedCacheSize, cache.size());
   for (int i = 0; i < 500; ++i) {
     cache.put(i, i);
     Assert.assertEquals(++expectedCacheSize, cache.size());
   }
   cache.put(500, 500);
   Assert.assertEquals(expectedCacheSize, cache.size());
   final TreeMap<Integer, Integer> sortedMap = new TreeMap<Integer, Integer>(cache);
   Assert.assertEquals(expectedCacheSize, sortedMap.size());
   Assert.assertEquals(1, sortedMap.firstKey().intValue());
   Assert.assertEquals(500, sortedMap.lastKey().intValue());
 }