DefaultIndexHandler implements IndexHandler<K, V> { protected List<Object> executeArithmetic(final ArithmeticCriteria arithmeticCriteria) { final CacheIndex cacheIndex = indexes.get(arithmeticCriteria.getAttributeName()); if (cacheIndex == null) { throw new IndexNotFoundException(); } return arithmeticCriteria.meets(cacheIndex); } 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 executeArithmetic() { String attributeName = "name"; List<Object> objects = new ArrayList<Object>(); doReturn(attributeName).when(arithmeticCriteria).getAttributeName(); doReturn(cacheIndex).when(indexes).get(attributeName); doReturn(objects).when(arithmeticCriteria).meets(cacheIndex); List<Object> actualObjects = handler.executeArithmetic(arithmeticCriteria); assertEquals(objects, actualObjects); }
@Test(expected = IndexNotFoundException.class) public void executeArithmeticThrowsIndexNotFoundException() { String attributeName = "name"; doReturn(attributeName).when(arithmeticCriteria).getAttributeName(); doReturn(null).when(indexes).get(attributeName); handler.executeArithmetic(arithmeticCriteria); }