!87 提供一个自带默认值的Map

Merge pull request !87 from Ease/v5-dev
This commit is contained in:
Looly
2020-01-09 10:07:04 +08:00
committed by Gitee
2 changed files with 243 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package cn.hutool.core.map;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
public class TolerantMapTest {
private final TolerantMap<String, String> map = TolerantMap.of(new HashMap<>(), "default");
@Before
public void before() {
map.put("monday", "星期一");
map.put("tuesday", "星期二");
}
@Test
public void testSerialize() {
byte[] bytes = ObjectUtil.serialize(map);
TolerantMap<String, String> serializedMap = ObjectUtil.deserialize(bytes);
assert serializedMap != map;
assert map.equals(serializedMap);
}
@Test
public void testClone() {
TolerantMap<String, String> clonedMap = ObjectUtil.clone(map);
assert clonedMap != map;
assert map.equals(clonedMap);
}
@Test
public void testGet() {
assert "星期二".equals(map.get("tuesday"));
assert "default".equals(map.get(RandomUtil.randomString(6)));
}
}