import java.lang.IllegalStateException;
import java.util.concurrent.ConcurrentHashMap;

public class ConcurrentHashMapTest {

    public static void main(final String[] args)
    {
        final ConcurrentHashMap<String, String> concurrentHashMap = new ConcurrentHashMap<>();

        final String key = "key";
        final String value = "value";

        System.out.println("Put called with key=" + key + ", value=" + value + ".");
        concurrentHashMap.put(key, value);

        System.out.println("ConcurrentHashMap size=" + concurrentHashMap.size() + ".");

        System.out.println("Running nested computeIdPresent with null return");
        concurrentHashMap.computeIfPresent(key, (aKey, aValue) -> {
            concurrentHashMap.computeIfPresent(key, (bKey, bValue) -> {
                return null;
            });
            return null;
        });

        System.out.println("ConcurrentHashMap size=" + concurrentHashMap.size() + ".");

        System.out.println("Put called with key=" + key + ", value=" + value + ".");
        concurrentHashMap.put(key, value);

        final int mapSize = concurrentHashMap.size();
        final int expectedSize = 1;

        System.out.println("ConcurrentHashMap size=" + mapSize + ".");
        if (expectedSize != mapSize) {
            throw new IllegalStateException("Expected map to have size of value 1 after put operation.");
        }
    }
}
