DefaultIndexHandler implements IndexHandler<K, V> { public void remove(final K key, final V value) { for (final String attributeName : indexes.keySet()) { final Object indexedKey = getFieldValue(attributeName, value); if (indexedKey == null) { throw new NullPointerException(); } indexes.get(attributeName).remove(indexedKey, key); } } DefaultIndexHandler(); void addIndex(final String attributeName, final IndexType type); void add(final K key, final V value); void remove(final K key, final V value); void clear(); @SuppressWarnings("unchecked") List<K> execute(final Query query);  }
@Test public void remove() { String attributeName = "name"; MyObject object = new MyObject(); object.name = attributeName; Set<String> keySet = new HashSet<String>(); keySet.add(attributeName); doReturn(keySet).when(indexes).keySet(); doReturn(cacheIndex).when(indexes).get(attributeName); doNothing().when(cacheIndex).remove(object, object); handler.remove(object, object); verify(cacheIndex).remove(attributeName, object); verify(indexes).get(attributeName); }