CollectionView implements Collection<E> { public boolean retainAll(Collection<?> c) { return this.collection.retainAll(c); } CollectionView(Collection<E> collection); boolean add(E element); boolean addAll(Collection<? extends E> collection); void clear(); boolean contains(Object o); boolean containsAll(Collection<?> c); boolean isEmpty(); Iterator<E> iterator(); boolean remove(Object o); boolean removeAll(Collection<?> c); boolean retainAll(Collection<?> c); int size(); Object[] toArray(); T[] toArray(T[] a); String toString();  }
@Test public void testRetainAll() { Collection retain = Arrays.asList("1", "2", "3"); assertTrue(this.source.isEmpty()); assertFalse(this.testobj.retainAll(retain)); assertTrue(this.source.isEmpty()); for (int i = 1; i <= 5; ++i) { this.source.add(String.valueOf(i)); assertEquals(i > 3, this.testobj.retainAll(retain)); assertEquals(i < 3 ? i : 3, this.source.size()); if (i > 2) { assertTrue(this.source.containsAll(retain)); assertTrue(retain.containsAll(this.source)); } } for (int i = 4; i <= 10; ++i) { this.source.add(String.valueOf(i)); } assertTrue(this.testobj.retainAll(retain)); assertEquals(3, this.testobj.size()); assertTrue(this.source.containsAll(retain)); assertTrue(retain.containsAll(this.source)); assertTrue(this.testobj.retainAll(Collections.emptyList())); assertTrue(this.source.isEmpty()); }