@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) public void testRemoveAtIndex_negative() { try { getList().remove(-1); fail("remove(-1) should throw"); } catch (IndexOutOfBoundsException expected) { } expectUnchanged(); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) public void testAddAllAtIndex_withDuplicates() { MinimalCollection<E> elementsToAdd = MinimalCollection.of(e0(), e1(), e0(), e1()); assertTrue("addAll(n, hasDuplicates) should return true", getList().addAll(0, elementsToAdd)); expectAdded(0, e0(), e1(), e0(), e1()); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) public void testAddAtIndex_negative() { try { getList().add(-1, e3()); fail("add(-1, e) should throw"); } catch (IndexOutOfBoundsException expected) { } expectUnchanged(); expectMissing(e3()); }
@ListFeature.Require(SUPPORTS_SET) public void testReplaceAll() { getList().replaceAll(e -> samples.e3()); expectContents(Collections.nCopies(getNumElements(), samples.e3())); }
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) @CollectionSize.Require(absent = ZERO) public void testRemoveAtIndex_last() { runRemoveTest(getNumElements() - 1); }
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) @CollectionSize.Require(absent = {ZERO, ONE}) public void testRemoveAtIndex_middle() { runRemoveTest(getNumElements() / 2); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) public void testAddAllAtIndex_nullCollectionReference() { try { getList().addAll(0, null); fail("addAll(n, null) should throw"); } catch (NullPointerException expected) { } expectUnchanged(); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionSize.Require(absent = ZERO) public void testAddAllAtIndex_end() { assertTrue( "addAll(end, disjoint) should return true", getList().addAll(getNumElements(), createDisjointCollection())); expectAdded(getNumElements(), createDisjointCollection()); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionFeature.Require(ALLOWS_NULL_VALUES) public void testAddAllAtIndex_nullSupported() { List<E> containsNull = singletonList(null); assertTrue("addAll(n, containsNull) should return true", getList().addAll(0, containsNull)); /* * We need (E) to force interpretation of null as the single element of a * varargs array, not the array itself */ expectAdded(0, (E) null); }
@ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) public void testAddAllAtIndex_unsupportedNothing() { try { assertFalse( "addAll(n, nothing) should return false or throw", getList().addAll(0, emptyCollection())); } catch (UnsupportedOperationException tolerated) { } expectUnchanged(); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionSize.Require(absent = ZERO) public void testAddAllAtIndex_supportedAllPresent() { assertTrue( "addAll(n, allPresent) should return true", getList().addAll(0, MinimalCollection.of(e0()))); expectAdded(0, e0()); }
@CollectionSize.Require(absent = ZERO) @ListFeature.Require(SUPPORTS_SET) @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) public void testSet_nullUnsupported() { try { getList().set(aValidIndex(), null); fail("set(null) should throw NullPointerException"); } catch (NullPointerException expected) { } expectUnchanged(); }
@CollectionSize.Require(absent = ZERO) @ListFeature.Require(absent = SUPPORTS_SET) public void testSet_unsupported() { try { getList().set(aValidIndex(), e3()); fail("set() should throw UnsupportedOperationException"); } catch (UnsupportedOperationException expected) { } expectUnchanged(); }
@ListFeature.Require(SUPPORTS_SET) public void testSet_indexTooLow() { try { getList().set(-1, e3()); fail("set(-1) should throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException expected) { } expectUnchanged(); }
@ListFeature.Require(SUPPORTS_SET) @CollectionSize.Require(absent = ZERO) public void testSet() { doTestSet(e3()); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionSize.Require(absent = ZERO) public void testAddAtIndex_end() { getList().add(getNumElements(), e3()); expectAdded(getNumElements(), e3()); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionSize.Require(absent = ZERO) public void testAddAtIndex_supportedPresent() { getList().add(0, e0()); expectAdded(0, e0()); }
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) @CollectionSize.Require(absent = {ZERO, ONE}) public void testSubList_subListRemoveAffectsOriginalLargeList() { List<E> subList = getList().subList(1, 3); subList.remove(e2()); List<E> expected = Helpers.copyToList(createSamplesArray()); expected.remove(2); expectContents(expected); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) public void testAddAllAtIndex_nullUnsupported() { List<E> containsNull = singletonList(null); try { getList().addAll(0, containsNull); fail("addAll(n, containsNull) should throw"); } catch (NullPointerException expected) { } expectUnchanged(); expectNullMissingWhenNullUnsupported( "Should not contain null after unsupported addAll(n, containsNull)"); }
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) public void testAddAllAtIndex_supportedNothing() { assertFalse("addAll(n, nothing) should return false", getList().addAll(0, emptyCollection())); expectUnchanged(); }