Ejemplo n.º 1
0
  public void testIsEmpty() {
    Cache<String, String> cache = initialize();

    assertFalse(cache.isEmpty());
    cache.clear();
    assertTrue(cache.isEmpty());
  }
Ejemplo n.º 2
0
  public void testSize() {
    Cache<String, String> cache = initialize();

    assertEquals(3, cache.size());
    cache.clear();
    assertEquals(0, cache.size());
  }
Ejemplo n.º 3
0
  private Cache<String, String> initialize() {
    Cache<String, String> cache = new Unlimited<String, String>();

    assertNull(cache.put("first key", "first value"));
    assertNull(cache.put("second key", "second value"));
    assertNull(cache.put("third key", "third value"));

    return cache;
  }
Ejemplo n.º 4
0
  public void testValues() {
    Cache<String, String> cache = initialize();

    Collection<String> col = cache.values();

    assertEquals(3, col.size());
    assertTrue(col.contains("first value"));
    assertTrue(col.contains("second value"));
    assertTrue(col.contains("third value"));
  }
Ejemplo n.º 5
0
  public void testKeySet() {
    Cache<String, String> cache = initialize();

    Set<String> set = cache.keySet();

    assertEquals(3, set.size());
    assertTrue(set.contains("first key"));
    assertTrue(set.contains("second key"));
    assertTrue(set.contains("third key"));
  }
Ejemplo n.º 6
0
  public void testPut() {
    Cache<String, String> cache = initialize();

    assertEquals("third value", cache.put("third key", "alternate third value"));
    assertNull(cache.put("fourth key", "forth value"));

    assertTrue(cache.containsKey("first key"));
    assertTrue(cache.containsKey("second key"));
    assertTrue(cache.containsKey("third key"));
    assertTrue(cache.containsKey("fourth key"));
    assertFalse(cache.containsKey("fifth key"));
  }
Ejemplo n.º 7
0
  public void testBasics() {
    assertEquals("unlimited", Unlimited.TYPE);

    Cache<String, String> cache = new Unlimited<String, String>();
    assertTrue(cache instanceof Unlimited);

    assertEquals("unlimited", cache.getType());

    assertFalse(cache.containsKey("first key"));
    assertFalse(cache.containsKey("second key"));

    assertNull(cache.put("first key", "first value"));

    assertTrue(cache.containsKey("first key"));
    assertFalse(cache.containsKey("second key"));

    assertNull(cache.put("second key", "second value"));

    assertTrue(cache.containsKey("first key"));
    assertTrue(cache.containsKey("second key"));
  }
Ejemplo n.º 8
0
  public void testEntrySet() {
    Cache<String, String> cache = initialize();

    Set<Map.Entry<String, String>> set = cache.entrySet();

    assertEquals(3, set.size());

    HashMap<String, String> map = new HashMap<String, String>();
    for (Map.Entry<String, String> entry : set) {
      map.put(entry.getKey(), entry.getValue());
    }

    assertTrue(map.containsKey("first key"));
    assertEquals("first value", map.get("first key"));

    assertTrue(map.containsKey("second key"));
    assertEquals("second value", map.get("second key"));

    assertTrue(map.containsKey("third key"));
    assertEquals("third value", map.get("third key"));
  }
Ejemplo n.º 9
0
  public void testRemove() {
    Cache<String, String> cache = initialize();

    assertEquals("third value", cache.remove("third key"));

    assertTrue(cache.containsKey("first key"));
    assertTrue(cache.containsKey("second key"));
    assertFalse(cache.containsKey("third key"));
    assertFalse(cache.containsKey("fourth key"));
    assertFalse(cache.containsKey("fifth key"));
  }
Ejemplo n.º 10
0
  public void testClear() {
    Cache<String, String> cache = initialize();

    cache.clear();

    assertFalse(cache.containsKey("first key"));
    assertFalse(cache.containsKey("second key"));
    assertFalse(cache.containsKey("third key"));
    assertFalse(cache.containsKey("fourth key"));
    assertFalse(cache.containsKey("fifth key"));
  }
Ejemplo n.º 11
0
  public void testGet() {
    Cache<String, String> cache = initialize();

    assertEquals("first value", cache.get("first key"));
    assertEquals("second value", cache.get("second key"));
    assertEquals("third value", cache.get("third key"));
    assertNull(cache.get("fourth key"));
    assertNull(cache.get("fifth key"));
  }
Ejemplo n.º 12
0
  public void testContainsValue() {
    Cache<String, String> cache = initialize();

    assertTrue(cache.containsValue("first value"));
    assertTrue(cache.containsValue("second value"));
    assertTrue(cache.containsValue("third value"));
    assertFalse(cache.containsValue("fourth value"));
    assertFalse(cache.containsValue("fifth value"));
  }
Ejemplo n.º 13
0
  public void testPutAll() {
    Cache<String, String> cache = initialize();

    HashMap<String, String> map = new HashMap<String, String>();
    map.put("fourth key", "forth value");
    map.put("fifth key", "fifth value");

    cache.putAll(map);

    assertTrue(cache.containsKey("first key"));
    assertTrue(cache.containsKey("second key"));
    assertTrue(cache.containsKey("third key"));
    assertTrue(cache.containsKey("fourth key"));
    assertTrue(cache.containsKey("fifth key"));
  }