MapOfSets implements MultiMap<K, V> { @Override public boolean put(final K key, final V value) { final Set<V> values = multiMap.computeIfAbsent(key, k -> createSet()); return values.add(value); } MapOfSets(final Map<K, Set<V>> multiMap);  MapOfSets(final Map<K, Set<V>> multiMap, final Class<? extends Set> setClass); @Override boolean put(final K key, final V value); @Override void put(final K key, final Collection<V> value); @Override Collection<V> get(final K key); @Override Set<K> keySet(); Collection<Map.Entry<K, Set<V>>> entrySet(); @Override void clear(); Map<K, Set<V>> getWrappedMap();  }
@Test public void shouldPutValueInExistingMapSet() throws StoreException { final String key = "key1"; final String value = "value1"; final Map<String, Set<String>> map = new HashMap<>(); final Set<String> set = mock(Set.class); final MapOfSets<String, String> mapOfSets = new MapOfSets<>(map); map.put(key, set); given(set.add(value)).willReturn(true); final boolean putResult = mapOfSets.put(key, value); assertTrue(putResult); verify(set).add(value); }