use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.
the class ConcurrentHashMap8Test method testComputeIfAbsent.
/**
* computeIfAbsent adds when the given key is not present
*/
public void testComputeIfAbsent() {
ConcurrentMap map = map5();
map.computeIfAbsent(six, (x) -> "Z");
assertTrue(map.containsKey(six));
}
use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.
the class ConcurrentHashMap8Test method testCompute3.
/**
* compute replaces when the given key is present
*/
public void testCompute3() {
ConcurrentMap map = map5();
assertEquals("Z", map.compute(one, (x, y) -> "Z"));
}
use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.
the class ConcurrentHashMapTest method testReplaceValue2_NullPointerException.
/**
* replace(x, null, y) throws NPE
*/
public void testReplaceValue2_NullPointerException() {
ConcurrentMap c = map();
try {
c.replace("whatever", null, "A");
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.
the class ConcurrentHashMapTest method map5.
/**
* Returns a new map from Integers 1-5 to Strings "A"-"E".
*/
private static ConcurrentMap<Integer, String> map5() {
ConcurrentMap map = map();
assertTrue(map.isEmpty());
map.put(one, "A");
map.put(two, "B");
map.put(three, "C");
map.put(four, "D");
map.put(five, "E");
assertFalse(map.isEmpty());
assertEquals(5, map.size());
return map;
}
use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.
the class ConcurrentHashMapTest method testReplace.
/**
* replace fails when the given key is not present
*/
public void testReplace() {
ConcurrentMap map = map5();
assertNull(map.replace(six, "Z"));
assertFalse(map.containsKey(six));
}
Aggregations