Copilot commented on code in PR #713:
URL:
https://github.com/apache/commons-collections/pull/713#discussion_r3581338647
##########
src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java:
##########
@@ -339,6 +339,26 @@ void testIntCollectionAddAll() {
assertEquals(thirdNewElement, list.get(0), "Third new element should
be at index 0");
}
+ @Test
+ void testIntCollectionAddAllOutOfBoundsIndex() {
+ final SetUniqueList<Integer> list = new SetUniqueList<>(new
ArrayList<>(), new HashSet<>());
+ list.add(Integer.valueOf(1));
+ final Integer newElement = Integer.valueOf(2);
+
+ // an out-of-range index must be rejected before the uniqueness set is
mutated
+ assertThrows(IndexOutOfBoundsException.class, () -> list.add(5,
newElement));
+ assertFalse(list.contains(newElement), "rejected element leaked into
the uniqueness set");
+ assertEquals(list.size(), list.asSet().size(), "list and uniqueness
set diverged");
+ // otherwise the element is silently dropped on the next add
+ assertTrue(list.add(newElement));
+ assertEquals(newElement, list.get(1));
+
+ assertThrows(IndexOutOfBoundsException.class,
+ () -> list.addAll(9, Arrays.asList(Integer.valueOf(3),
Integer.valueOf(4))));
+ assertFalse(list.contains(Integer.valueOf(3)));
+ assertEquals(list.size(), list.asSet().size(), "list and uniqueness
set diverged");
Review Comment:
The addAll out-of-bounds assertion only checks that element `3` is absent.
Adding an explicit check for `4` makes the test more direct and ensures both
candidate inserts are verified as not leaking into the uniqueness set.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]