Reputation: 349
I have a problem, How to set value for this hashmap and mock it
Map <String, MultiValueMap<String, Integer>> idsrcMp = new HashMap<>(3);
Upvotes: 3
Views: 14465
Reputation: 17065
I'm not sure what you mean by "set value and mock it". You want to set values or mock it ?
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());
Upvotes: 4