/*
* with a HARD -> WEAK map, verify that the entry remains if there is no
* reference to key, but is deleted when the reference to value is gone
*/
Map<Integer, Integer> simpleMap = new MapMaker().weakValues().makeMap();
Integer bar = new Integer(42);
simpleMap.put(new Integer(32), bar);
Runtime.getRuntime().gc();
assertEquals(1, simpleMap.size());
bar = null;
Runtime.getRuntime().gc();
assertEquals(0, simpleMap.size());
/*
* with a WEAK -> WEAK map, verify that the entry is gone if there are no
* references to either the key or the value.
*/
simpleMap = new MapMaker().weakKeys().weakValues().makeMap();
Map<Integer, Integer> reverseMap = new MapMaker().weakKeys().weakValues().makeMap();
Integer foo = new Integer(32);
bar = new Integer(42);
simpleMap.put(foo, bar);
reverseMap.put(bar, foo);
Runtime.getRuntime().gc();