CollectionItem implements CacheItem<Collection<V>> { @SuppressWarnings("unchecked") public Collection<V> filter(Filter filter) { List<Object> filteredObjects = filter.filter((List<Object>) objects); return (Collection<V>) filteredObjects; } CollectionItem(Collection<? extends V> objects); @SuppressWarnings("unchecked") Collection<V> getValue(); @SuppressWarnings("unchecked") Collection<V> filter(Filter filter);  }
@Test @SuppressWarnings("unchecked") public void filter() { Item item = new Item(2); List<Item> items = new ArrayList<Item>(); items.add(item); CollectionItem<Item> collectionItem = new CollectionItem<Item>(items); doReturn(items).when(filter).filter(anyList()); Collection<Item> filteredItems = collectionItem.filter(filter); assertTrue(filteredItems.contains(item)); }