package com.feilong.core.util.maputiltest;
import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import com.feilong.core.util.MapUtil;
public class MapUtilGetSubMapTest{
@Test
public void testGetSubMap(){
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("a", 3007);
map.put("b", 3001);
map.put("c", 3001);
map.put("d", 3003);
Map<String, Integer> subMap = MapUtil.getSubMap(map, "a", "c");
assertThat(subMap, allOf(hasEntry("a", 3007), hasEntry("c", 3001), not(hasKey("b")), not(hasKey("d"))));
}
@Test
public void testGetSubMap1(){
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("a", 3007);
map.put("b", 3001);
map.put("c", 3001);
map.put("d", 3003);
Map<String, Integer> subMap = MapUtil.getSubMap(map, "a", "c", "f");
assertThat(subMap, allOf(hasEntry("a", 3007), hasEntry("c", 3001), not(hasKey("b")), not(hasKey("d"))));
}
@Test
public void testGetSubMapNullKeys(){
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("a", 3007);
map.put("b", 3001);
map.put("c", 3001);
map.put("d", 3003);
assertEquals(map, MapUtil.getSubMap(map, null));
}
@Test
public void testGetSubMapEmptyKeys(){
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("a", 3007);
map.put("b", 3001);
map.put("c", 3001);
map.put("d", 3003);
assertEquals(map, MapUtil.getSubMap(map));
}
@Test
public void testGetSubMapNullMap(){
assertEquals(emptyMap(), MapUtil.getSubMap(null, "a", "c"));
}
@Test
public void testGetSubMapEmptyMap(){
assertEquals(emptyMap(), MapUtil.getSubMap(new HashMap<>(), "a", "c"));
assertEquals(emptyMap(), MapUtil.getSubMap(emptyMap(), "a", "c"));
}
}