Code example for ConcurrentMap

Methods: replace, containsKey, containsValue, get, isEmpty, keySet, put, size, values

0
 
		String testKey = new String("testKey");
		Object testValue1 = new Object(); 
		Object testValue2 = new Object(); 
 
		Assert.assertFalse(concurrentMap.containsKey(testKey));
		Assert.assertTrue(finalizeActions.isEmpty());
		Assert.assertNull(concurrentMap.put(testKey, testValue1));
		Assert.assertTrue(concurrentMap.containsKey(testKey));
		Assert.assertSame(testValue1, concurrentMap.get(testKey));
		Assert.assertTrue(concurrentMap.containsValue(testValue1));
		Assert.assertEquals(1, finalizeActions.size());
		Assert.assertSame(testValue1, concurrentMap.put(testKey, testValue2));
		Assert.assertTrue(concurrentMap.containsKey(testKey));
		Assert.assertSame(testValue2, concurrentMap.get(testKey));
		Assert.assertFalse(concurrentMap.containsValue(testValue1));
		Assert.assertTrue(concurrentMap.containsValue(testValue2));
		Assert.assertEquals(1, finalizeActions.size());
 
		Set<String> keySet = concurrentMap.keySet();
 
		Iterator<String> keyIterator = keySet.iterator();
 
		Assert.assertSame(testKey, keyIterator.next());
 
		Collection<Object> values = concurrentMap.values();
 
		Iterator<Object> valueIterator = values.iterator();
 
		Assert.assertSame(testValue2, valueIterator.next());
		Assert.assertSame(
			testValue2, concurrentMap.replace(testKey, new Object()));
		Assert.assertEquals(1, finalizeActions.size());
		Assert.assertEquals(1, concurrentMap.size());
 
		testKey = null;
 
		if (fullGC) {
			GCUtil.fullGC(); 
		} 
		else { 
			GCUtil.gc(); 
		} 
 
		ReflectionTestUtil.invoke( 
			FinalizeManager.class, "_pollingCleanup", new Class<?>[0]);
 
		Assert.assertTrue(finalizeActions.isEmpty());
		Assert.assertTrue(concurrentMap.isEmpty());
	} 
 
}