@Test public void testWithNullAsKeyAndValue() throws Exception { final T cache = getInstance(1000, 1000); assertEquals(0, (long) cache.size()); assertFalse(cache.contains(null)); assertNull(cache.get(null)); // Add entry with null as key and value ... cache.put(null, null); assertEquals(1, (long) cache.size()); assertTrue(cache.contains(null)); assertNull(cache.get(null)); // Add another entry ... cache.put(new Object(), new Object()); assertEquals(2, (long) cache.size()); // Remove entry with null as key ... assertNull(cache.remove(null).getValue()); assertEquals(1, (long) cache.size()); assertFalse(cache.contains(null)); assertNull(cache.get(null)); // Try to remove entry with null as key again ... assertNull(cache.remove(null)); assertEquals(1, (long) cache.size()); assertFalse(cache.contains(null)); assertNull(cache.get(null)); }
@Test public void testWithMaxSize1() { final T cache = getInstance(1000, 1); final Object o1 = new Object(); cache.put(o1, o1); final Object o2 = new Object(); cache.put(o2, o2); assertEquals(1, (long) cache.size()); assertFalse(cache.contains(o1)); assertTrue(cache.contains(o2)); }
@Test public void testWithNullAsValue() throws Exception { final T cache = getInstance(1000, 1000); final Object o = new Object(); assertEquals(0, (long) cache.size()); assertFalse(cache.contains(o)); assertNull(cache.get(o)); // Add entry with null as value ... cache.put(o, null); assertEquals(1, (long) cache.size()); assertTrue(cache.contains(o)); assertNull(cache.get(o)); // Remove entry with null as value ... assertNull(cache.remove(o).getValue()); assertEquals(0, (long) cache.size()); assertFalse(cache.contains(o)); assertNull(cache.get(o)); // Try to remove entry with null as value again ... assertNull(cache.remove(o)); assertEquals(0, (long) cache.size()); assertFalse(cache.contains(o)); assertNull(cache.get(o)); }