@CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION) @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) public void testAddAtIndexConcurrentWithIteration() { try { Iterator<E> iterator = collection.iterator(); getList().add(0, e3()); iterator.next(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } }
@ListFeature.Require(SUPPORTS_SET) @CollectionSize.Require(absent = ZERO) public void testSubList_originalListSetAffectsSubList() { List<E> subList = getList().subList(0, 1); getList().set(0, e3()); assertEquals( "A set() call to a list after a sublist has been created " + "should be reflected in the sublist", Collections.singletonList(e3()), subList); }
@ListFeature.Require(SUPPORTS_SET) @CollectionSize.Require(absent = {ZERO, ONE}) public void testSubList_subListSetAffectsOriginalLargeList() { List<E> subList = getList().subList(1, 2); subList.set(0, e3()); List<E> expected = Helpers.copyToList(createSamplesArray()); expected.set(1, e3()); expectContents(expected); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) public void testAddAllAtIndex_supportedNothing() { assertFalse("addAll(n, nothing) should return false", getList().addAll(0, emptyCollection())); expectUnchanged(); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionSize.Require(absent = ZERO) public void testAddAllAtIndex_supportedSomePresent() { assertTrue( "addAll(n, allPresent) should return true", getList().addAll(0, MinimalCollection.of(e0(), e3()))); expectAdded(0, e0(), e3()); }
@CollectionSize.Require(ZERO) @ListFeature.Require(absent = SUPPORTS_SET) public void testSet_unsupportedByEmptyList() { try { getList().set(0, e3()); fail("set() should throw UnsupportedOperationException or IndexOutOfBoundsException"); } catch (UnsupportedOperationException | IndexOutOfBoundsException tolerated) { } expectUnchanged(); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(ALLOWS_NULL_VALUES) @ListFeature.Require(SUPPORTS_SET) public void testSet_null() { doTestSet(null); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) public void testAddAtIndex_tooLarge() { try { getList().add(getNumElements() + 1, e3()); fail("add(size + 1, e) should throw"); } catch (IndexOutOfBoundsException expected) { } expectUnchanged(); expectMissing(e3()); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) public void testAddAtIndex_supportedNotPresent() { getList().add(0, e3()); expectAdded(0, e3()); }
@ListFeature.Require(SUPPORTS_SET) @CollectionSize.Require(absent = ZERO) public void testSubList_subListSetAffectsOriginal() { List<E> subList = getList().subList(0, 1); subList.set(0, e3()); List<E> expected = Helpers.copyToList(createSamplesArray()); expected.set(0, e3()); expectContents(expected); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) public void testAddAllAtIndex_negative() { try { getList().addAll(-1, MinimalCollection.of(e3())); fail("addAll(-1, e) should throw"); } catch (IndexOutOfBoundsException expected) { } expectUnchanged(); expectMissing(e3()); }
@ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) @CollectionSize.Require(absent = ZERO) public void testAddAllAtIndex_unsupportedSomePresent() { try { getList().addAll(0, MinimalCollection.of(e0(), e3())); fail("addAll(n, allPresent) should throw"); } catch (UnsupportedOperationException expected) { } expectUnchanged(); expectMissing(e3()); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) public void testAddAtIndex_nullUnsupported() { try { getList().add(0, null); fail("add(n, null) should throw"); } catch (NullPointerException expected) { } expectUnchanged(); expectNullMissingWhenNullUnsupported("Should not contain null after unsupported add(n, null)"); }
@ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) public void testAddAtIndex_unsupportedNotPresent() { try { getList().add(0, e3()); fail("add(n, notPresent) should throw"); } catch (UnsupportedOperationException expected) { } expectUnchanged(); expectMissing(e3()); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionSize.Require(absent = {ZERO, ONE}) public void testSubList_subListAddAtIndexAffectsOriginalLargeList() { List<E> subList = getList().subList(2, 3); subList.add(0, e3()); expectAdded(2, e3()); }
@CollectionSize.Require(absent = ZERO) @ListFeature.Require(absent = SUPPORTS_SET) public void testReplaceAll_unsupported() { try { getList().replaceAll(e -> e); fail("replaceAll() should throw UnsupportedOperationException"); } catch (UnsupportedOperationException expected) { } expectUnchanged(); } }
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) @CollectionSize.Require(absent = ZERO) public void testRemoveAtIndex_first() { runRemoveTest(0); }
@ListFeature.Require(absent = SUPPORTS_REMOVE_WITH_INDEX) @CollectionSize.Require(absent = ZERO) public void testRemoveAtIndex_unsupported() { try { getList().remove(0); fail("remove(i) should throw"); } catch (UnsupportedOperationException expected) { } expectUnchanged(); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionFeature.Require(ALLOWS_NULL_VALUES) public void testAddAtIndex_nullSupported() { getList().add(0, null); expectAdded(0, (E) null); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionSize.Require(absent = {ZERO, ONE}) public void testAddAtIndex_middle() { getList().add(getNumElements() / 2, e3()); expectAdded(getNumElements() / 2, e3()); }