@Test public void testRemoveAllWithPredicateInterrupted() { addFromArray( this.set, newArray(this.k0, this.k1, this.k2, this.k3, this.k4, this.k5, this.k6, this.k7, this.k8)); final RuntimeException t = new RuntimeException(); try { // the assert below should never be triggered because of the exception // so give it an invalid value in case the thing terminates = initial size + 1 Assert.assertEquals( 10, this.set.removeAll( new KTypePredicate<KType>() { @Override public boolean apply(final KType v) { if (v == AbstractKTypeHashSetTest.this.key7) { throw t; } return v == AbstractKTypeHashSetTest.this.key2 || v == AbstractKTypeHashSetTest.this.key9 || v == AbstractKTypeHashSetTest.this.key5; }; })); Assert.fail(); } catch (final RuntimeException e) { // Make sure it's really our exception... if (e != t) { throw e; } } // And check if the set is in consistent state. We cannot predict the pattern, // but we know that since key7 throws an exception, key7 is still present in the set. Assert.assertTrue(this.set.contains(this.key7)); checkConsistency(); }