package com.alibaba.nacos.common.utils;

import org.junit.Assert;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class MapUtilsTest {

	@Test
	public void test_map() {
		Map<Object, Object> map = new HashMap<>();

		MapUtils.putIfValNoNull(map, "key-1", null);
		Assert.assertFalse(map.containsKey("key-1"));

		MapUtils.putIfValNoEmpty(map, "key-str", null);
		Assert.assertFalse(map.containsKey("key-str"));

		MapUtils.putIfValNoEmpty(map, "key-str", "");
		Assert.assertFalse(map.containsKey("key-str"));

		MapUtils.putIfValNoEmpty(map, "key-str", "1");
		Assert.assertTrue(map.containsKey("key-str"));

		MapUtils.putIfValNoEmpty(map, "key-list", null);
		Assert.assertFalse(map.containsKey("key-list"));

		MapUtils.putIfValNoEmpty(map, "key-list", Collections.emptyList());
		Assert.assertFalse(map.containsKey("key-list"));

		MapUtils.putIfValNoEmpty(map, "key-list", Collections.singletonList(1));
		Assert.assertTrue(map.containsKey("key-list"));

		MapUtils.putIfValNoEmpty(map, "key-map", null);
		Assert.assertFalse(map.containsKey("key-map"));

		MapUtils.putIfValNoEmpty(map, "key-map", Collections.emptyMap());
		Assert.assertFalse(map.containsKey("key-map"));

		Map<String, String> map1 = new HashMap<>();
		map1.put("1123", "123");

		MapUtils.putIfValNoEmpty(map, "key-map", map1);
		Assert.assertTrue(map.containsKey("key-map"));
	}

}
@@ -260,24 +260,38 @@
 new HashMap%3C
+Object, Object
 %3E();%0A%0A%09%09MapU
@@ -1291,16 +1291,30 @@
 HashMap%3C
+String, String
 %3E();%0A%09%09m

fix unit tests that do not conform to PMD