use of java.util.WeakHashMap in project robovm by robovm.
the class WeakHashMapTest method test_putLjava_lang_ObjectLjava_lang_Object.
/**
* java.util.WeakHashMap#put(java.lang.Object, java.lang.Object)
*/
public void test_putLjava_lang_ObjectLjava_lang_Object() {
// Test for method java.lang.Object
// java.util.WeakHashMap.put(java.lang.Object, java.lang.Object)
WeakHashMap map = new WeakHashMap();
// add null key
map.put(null, "value");
System.gc();
System.gc();
FinalizationTester.induceFinalization();
// Cause objects in queue to be removed
map.remove("nothing");
assertEquals("null key was removed", 1, map.size());
}
use of java.util.WeakHashMap in project robovm by robovm.
the class WeakHashMapTest method test_values.
/**
* java.util.WeakHashMap#values()
*/
public void test_values() {
// Test for method java.util.Set java.util.WeakHashMap.values()
whm = new WeakHashMap();
for (int i = 0; i < 100; i++) whm.put(keyArray[i], valueArray[i]);
List keys = Arrays.asList(keyArray);
List values = Arrays.asList(valueArray);
Collection valuesCollection = whm.values();
assertEquals("Incorrect number of keys returned,", 100, valuesCollection.size());
Iterator it = valuesCollection.iterator();
while (it.hasNext()) {
Object value = it.next();
assertTrue("Invalid map entry returned--bad value", values.contains(value));
}
keys = null;
values = null;
keyArray[50] = null;
int count = 0;
do {
System.gc();
System.gc();
FinalizationTester.induceFinalization();
count++;
} while (count <= 5 && valuesCollection.size() == 100);
assertEquals("Incorrect number of keys returned after gc,", 99, valuesCollection.size());
}
use of java.util.WeakHashMap in project robovm by robovm.
the class WeakHashMapTest method test_keySet.
/**
* java.util.WeakHashMap#keySet()
*/
public void test_keySet() {
// Test for method java.util.Set java.util.WeakHashMap.keySet()
whm = new WeakHashMap();
for (int i = 0; i < 100; i++) whm.put(keyArray[i], valueArray[i]);
List keys = Arrays.asList(keyArray);
List values = Arrays.asList(valueArray);
Set keySet = whm.keySet();
assertEquals("Incorrect number of keys returned,", 100, keySet.size());
Iterator it = keySet.iterator();
while (it.hasNext()) {
Object key = it.next();
assertTrue("Invalid map entry returned--bad key", keys.contains(key));
}
keys = null;
values = null;
keyArray[50] = null;
int count = 0;
do {
System.gc();
System.gc();
FinalizationTester.induceFinalization();
count++;
} while (count <= 5 && keySet.size() == 100);
assertEquals("Incorrect number of keys returned after gc,", 99, keySet.size());
}
use of java.util.WeakHashMap in project robovm by robovm.
the class WeakHashMapTest method test_entrySet.
/**
* java.util.WeakHashMap#entrySet()
*/
public void test_entrySet() {
// Test for method java.util.Set java.util.WeakHashMap.entrySet()
whm = new WeakHashMap();
for (int i = 0; i < 100; i++) whm.put(keyArray[i], valueArray[i]);
List keys = Arrays.asList(keyArray);
List values = Arrays.asList(valueArray);
Set entrySet = whm.entrySet();
assertTrue("Incorrect number of entries returned--wanted 100, got: " + entrySet.size(), entrySet.size() == 100);
Iterator it = entrySet.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
assertTrue("Invalid map entry returned--bad key", keys.contains(entry.getKey()));
assertTrue("Invalid map entry returned--bad key", values.contains(entry.getValue()));
}
keys = null;
values = null;
keyArray[50] = null;
int count = 0;
do {
System.gc();
System.gc();
FinalizationTester.induceFinalization();
count++;
} while (count <= 5 && entrySet.size() == 100);
assertTrue("Incorrect number of entries returned after gc--wanted 99, got: " + entrySet.size(), entrySet.size() == 99);
}
use of java.util.WeakHashMap in project j2objc by google.
the class AbstractMapTest method test_removeLjava_lang_Object.
/**
* java.util.AbstractMap#remove(java.lang.Object)
*/
public void test_removeLjava_lang_Object() {
Object key = new Object();
Object value = new Object();
AbstractMap map1 = new HashMap(0);
map1.put("key", value);
assertSame("HashMap(0)", map1.remove("key"), value);
AbstractMap map4 = new IdentityHashMap(1);
map4.put(key, value);
assertSame("IdentityHashMap", map4.remove(key), value);
AbstractMap map5 = new LinkedHashMap(122);
map5.put(key, value);
assertSame("LinkedHashMap", map5.remove(key), value);
AbstractMap map6 = new TreeMap(new Comparator() {
// Bogus comparator
public int compare(Object object1, Object object2) {
return 0;
}
});
map6.put(key, value);
assertSame("TreeMap", map6.remove(key), value);
AbstractMap map7 = new WeakHashMap();
map7.put(key, value);
assertSame("WeakHashMap", map7.remove(key), value);
AbstractMap aSpecialMap = new MyMap();
aSpecialMap.put(specialKey, specialValue);
Object valueOut = aSpecialMap.remove(specialKey);
assertSame("MyMap", valueOut, specialValue);
}
Aggregations