Skip to content

Commit

Permalink
BAEL-4686:Allow Null test
Browse files Browse the repository at this point in the history
  • Loading branch information
ati083 committed Nov 23, 2020
1 parent 74eb0bd commit 4f252b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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;
Expand Down

0 comments on commit 4f252b7

Please sign in to comment.