use of java.util.IdentityHashMap in project j2objc by google.
the class IdentityHashMapTest method test_entrySet_removeAll.
/**
* @tests java.util.IdentityHashMap#entrySet()
* @tests java.util.IdentityHashMap#remove(java.lang.Object)
*/
public void test_entrySet_removeAll() {
IdentityHashMap map = new IdentityHashMap();
for (int i = 0; i < 1000; i++) {
map.put(new Integer(i), new Integer(i));
}
Set set = map.entrySet();
set.removeAll(set);
assertEquals("did not remove all elements in the map", 0, map.size());
assertTrue("did not remove all elements in the entryset", set.isEmpty());
Iterator it = set.iterator();
assertTrue("entrySet iterator still has elements", !it.hasNext());
}
use of java.util.IdentityHashMap in project j2objc by google.
the class IdentityHashMapTest method test_null_Keys_and_Values.
/**
* @tests java.util.IdentityHashMap#containsKey(java.lang.Object)
* @tests java.util.IdentityHashMap#containsValue(java.lang.Object)
* @tests java.util.IdentityHashMap#put(java.lang.Object, java.lang.Object)
* @tests java.util.IdentityHashMap#get(java.lang.Object)
*/
public void test_null_Keys_and_Values() {
// tests with null keys and values
IdentityHashMap map = new IdentityHashMap();
Object result;
// null key and null value
result = map.put(null, null);
assertTrue("testA can not find null key", map.containsKey(null));
assertTrue("testA can not find null value", map.containsValue(null));
assertNull("testA can not get null value for null key", map.get(null));
assertNull("testA put returned wrong value", result);
// null value
String value = "a value";
result = map.put(null, value);
assertTrue("testB can not find null key", map.containsKey(null));
assertTrue("testB can not find a value with null key", map.containsValue(value));
assertTrue("testB can not get value for null key", map.get(null) == value);
assertNull("testB put returned wrong value", result);
// a null key
String key = "a key";
result = map.put(key, null);
assertTrue("testC can not find a key with null value", map.containsKey(key));
assertTrue("testC can not find null value", map.containsValue(null));
assertNull("testC can not get null value for key", map.get(key));
assertNull("testC put returned wrong value", result);
// another null key
String anothervalue = "another value";
result = map.put(null, anothervalue);
assertTrue("testD can not find null key", map.containsKey(null));
assertTrue("testD can not find a value with null key", map.containsValue(anothervalue));
assertTrue("testD can not get value for null key", map.get(null) == anothervalue);
assertTrue("testD put returned wrong value", result == value);
// remove a null key
result = map.remove(null);
assertTrue("testE remove returned wrong value", result == anothervalue);
assertTrue("testE should not find null key", !map.containsKey(null));
assertTrue("testE should not find a value with null key", !map.containsValue(anothervalue));
assertNull("testE should not get value for null key", map.get(null));
}
use of java.util.IdentityHashMap in project j2objc by google.
the class IdentityHashMapTest method test_sets.
/**
* @tests java.util.IdentityHashMap#entrySet()
* @tests java.util.IdentityHashMap#keySet()
* @tests java.util.IdentityHashMap#values()
*/
public void test_sets() {
// tests with null keys and values
IdentityHashMap map = new IdentityHashMap();
// null key and null value
map.put("key", "value");
map.put(null, null);
map.put("a key", null);
map.put("another key", null);
Set keyset = map.keySet();
Collection valueset = map.values();
Set entries = map.entrySet();
Iterator it = entries.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
assertTrue("EntrySetIterator can not find entry ", entries.contains(entry));
assertTrue("entry key not found in map", map.containsKey(entry.getKey()));
assertTrue("entry value not found in map", map.containsValue(entry.getValue()));
assertTrue("entry key not found in the keyset", keyset.contains(entry.getKey()));
assertTrue("entry value not found in the valueset", valueset.contains(entry.getValue()));
}
}
use of java.util.IdentityHashMap in project j2objc by google.
the class AbstractMapTest method test_keySet.
/**
* java.util.AbstractMap#keySet()
*/
public void test_keySet() {
AbstractMap map1 = new HashMap(0);
assertSame("HashMap(0)", map1.keySet(), map1.keySet());
AbstractMap map2 = new HashMap(10);
assertSame("HashMap(10)", map2.keySet(), map2.keySet());
Map map3 = Collections.EMPTY_MAP;
assertSame("EMPTY_MAP", map3.keySet(), map3.keySet());
AbstractMap map4 = new IdentityHashMap(1);
assertSame("IdentityHashMap", map4.keySet(), map4.keySet());
AbstractMap map5 = new LinkedHashMap(122);
assertSame("LinkedHashMap", map5.keySet(), map5.keySet());
AbstractMap map6 = new TreeMap();
assertSame("TreeMap", map6.keySet(), map6.keySet());
AbstractMap map7 = new WeakHashMap();
assertSame("WeakHashMap", map7.keySet(), map7.keySet());
}
use of java.util.IdentityHashMap in project randomizedtesting by randomizedtesting.
the class TextReport method emitBufferedEvents.
private void emitBufferedEvents(AggregatedSuiteResultEvent e) throws IOException {
final IdentityHashMap<TestFinishedEvent, AggregatedTestResultEvent> eventMap = new IdentityHashMap<>();
for (AggregatedTestResultEvent tre : e.getTests()) {
eventMap.put(tre.getTestFinishedEvent(), tre);
}
final boolean emitOutput = (outputMode != OutputMode.NEVER) && ((outputMode == OutputMode.ALWAYS && !isPassthrough()) || (outputMode == OutputMode.ONERROR && !e.isSuccessful()));
for (IEvent event : e.getEventStream()) {
switch(event.getType()) {
case APPEND_STDOUT:
if (emitOutput)
((IStreamEvent) event).copyTo(outStream);
break;
case APPEND_STDERR:
if (emitOutput)
((IStreamEvent) event).copyTo(errStream);
break;
case TEST_FINISHED:
assert eventMap.containsKey(event);
final AggregatedTestResultEvent aggregated = eventMap.get(event);
if (displayStatus.get(aggregated.getStatus())) {
flushOutput();
emitStatusLine(aggregated, aggregated.getStatus(), aggregated.getExecutionTime());
}
default:
break;
}
}
if (emitOutput) {
flushOutput();
}
}
Aggregations