Code example for IdentityHashMap

Methods: containsKey, containsValue, get, put, remove

0
	 * @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));
	} 
 
    /** 
     * @tests java.util.IdentityHashMap#put(java.lang.Object, java.lang.Object) 
     */