Ejemplo n.º 1
0
 public void testExpiry() throws Exception {
   cache.put(1, "apple");
   assertEquals("apple", cache.get(1));
   assertFalse(cache.isEmpty());
   Clock.setTime(3000);
   assertNull(cache.get(1));
   assertTrue(cache.isEmpty());
 }
Ejemplo n.º 2
0
  public void testPartialExpiry() throws Exception {
    // Add an apple, it will expire at 2000
    cache.put(1, "apple");
    Clock.setTime(1500);
    // Add an orange, it will expire at 2500
    cache.put(2, "orange");

    assertEquals("apple", cache.get(1));
    assertEquals("orange", cache.get(2));
    assertEquals(2, cache.size());

    // Set time to 2300 and check that only the apple has disappeared
    Clock.setTime(2300);

    assertNull(cache.get(1));
    assertEquals("orange", cache.get(2));
    assertEquals(1, cache.size());
  }
Ejemplo n.º 3
0
  public void testRemove() throws Exception {
    assertNull(cache.remove(new Integer(1)));

    cache.put(new Integer(1), "apple");

    assertEquals("apple", cache.remove(new Integer(1)));

    assertNull(cache.get(new Integer(1)));
    assertEquals(0, cache.size());
  }