210211212213214215216217218219220
Set retained = new HashSet(); for (int i = 1; i <= 10; i++) { set.add("item" + i); } set.retainAll(retained); assertEquals(0, set.size()); } @Test public void testRetainAll_whenArgumentHasSameElements() {
223224225226227228229230231232233
for (int i = 1; i <= 10; i++) { set.add("item" + i); retained.add("item" + i); } set.retainAll(retained); assertEquals(10, set.size()); } @Test(expected = NullPointerException.class) public void testRetainAll_whenCollectionNull() {
231232233234235236237238239240241
@Test(expected = NullPointerException.class) public void testRetainAll_whenCollectionNull() { ISet set = newSet(); Set retained = null; set.retainAll(retained); assertEquals(0, set.size()); } // ======================== contains - containsAll ========================== @Test