@CollectionFeature.Require(SUPPORTS_REMOVE) public void testClear() { collection.clear(); assertTrue("After clear(), a collection should be empty.", collection.isEmpty()); assertEquals(0, collection.size()); assertFalse(collection.iterator().hasNext()); }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testClear_unsupported() { try { collection.clear(); fail( "clear() should throw UnsupportedOperation if a collection does " + "not support it and is not empty."); } catch (UnsupportedOperationException expected) { } expectUnchanged(); }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) @CollectionSize.Require(ZERO) public void testClear_unsupportedByEmptyCollection() { try { collection.clear(); } catch (UnsupportedOperationException tolerated) { } expectUnchanged(); }
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) @CollectionSize.Require(SEVERAL) public void testClearConcurrentWithIteration() { try { Iterator<E> iterator = collection.iterator(); collection.clear(); iterator.next(); /* * We prefer for iterators to fail immediately on hasNext, but ArrayList * and LinkedList will notably return true on hasNext here! */ fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } } }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testClear() { collection.clear(); assertTrue("After clear(), a collection should be empty.", collection.isEmpty()); }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) @CollectionSize.Require(ZERO) public void testClear_unsupportedByEmptyCollection() { try { collection.clear(); } catch (UnsupportedOperationException tolerated) { } expectUnchanged(); }
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) @CollectionSize.Require(SEVERAL) public void testClearConcurrentWithIteration() { try { Iterator<E> iterator = collection.iterator(); collection.clear(); iterator.next(); /* * We prefer for iterators to fail immediately on hasNext, but ArrayList * and LinkedList will notably return true on hasNext here! */ fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } } }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testClear_unsupported() { try { collection.clear(); fail( "clear() should throw UnsupportedOperation if a collection does " + "not support it and is not empty."); } catch (UnsupportedOperationException expected) { } expectUnchanged(); }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testClear() { collection.clear(); assertTrue("After clear(), a collection should be empty.", collection.isEmpty()); assertEquals(0, collection.size()); assertFalse(collection.iterator().hasNext()); }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) @CollectionSize.Require(ZERO) public void testClear_unsupportedByEmptyCollection() { try { collection.clear(); } catch (UnsupportedOperationException tolerated) { } expectUnchanged(); }
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) @CollectionSize.Require(SEVERAL) public void testClearConcurrentWithIteration() { try { Iterator<E> iterator = collection.iterator(); collection.clear(); iterator.next(); /* * We prefer for iterators to fail immediately on hasNext, but ArrayList * and LinkedList will notably return true on hasNext here! */ fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } } }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testClear_unsupported() { try { collection.clear(); fail("clear() should throw UnsupportedOperation if a collection does " + "not support it and is not empty."); } catch (UnsupportedOperationException expected) { } expectUnchanged(); }