我有一个问题,如何设置此hashmap的值并模拟它
Map <String, MultiValueMap<String, Integer>> idsrcMp = new HashMap<>(3);
答案 0 :(得分:1)
我不确定你的意思是“设定值并嘲笑它”。您想设置值或模拟它吗?
Map<String, MultiValueMap<String, Integer>> idsrcMp = new HashMap<>(3);
MultiValueMap<String, Integer> multiValueMap = new LinkedMultiValueMap<>();
multiValueMap.put("item", Collections.emptyList()); // insert a List here
idsrcMp.put("first", multiValueMap);
Map map = Mockito.mock(Map.class);
MultiValueMap multiValueMap = Mockito.mock(MultiValueMap.class);
Mockito.when(map.get("mapItem")).thenReturn(multiValueMap);
Mockito.when(multiValueMap.get("multimapItem"))
.thenReturn(Collections.emptyList());