BAEL-4686:Allow Null test

This commit is contained in:
Amitabh Tiwari 2020-11-23 20:10:17 +05:30
parent bd6bc03c93
commit 2a1baae599
2 changed files with 28 additions and 1 deletions

View File

@ -0,0 +1,27 @@
package com.baeldung.map.concurrenthashmap;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.Assert;
import org.junit.Test;
public class NullAllowInMapTest {
@Test
public void allowOnlyNull_In_SynchronizedMap() {
Map<String, Integer> map = Collections
.synchronizedMap(new HashMap<String, Integer>());
map.put(null, 1);
Assert.assertTrue(map.get(null).equals(1));
}
@Test(expected = NullPointerException.class)
public void allowOnlyNull_In_ConcurrentHasMap() {
Map<String, Integer> map = new ConcurrentHashMap<>();
map.put(null, 1);
}
}

View File

@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Test;
public class ConcurrentHashMapVsSynchronizedMapPerformanceTest {
public class PerformanceTest {
public final static int THREAD_POOL_SIZE = 5;
public final static int TEST_ITERATIONS = 5;