garydgregory commented on code in PR #537:
URL:
https://github.com/apache/commons-collections/pull/537#discussion_r1740095339
##########
src/test/java/org/apache/commons/collections4/ListUtilsTest.java:
##########
@@ -102,6 +102,54 @@ public void testEquals() {
assertFalse(ListUtils.isEqualList(list1, list2));
}
+ @Test
+ public void testFindDuplicatesWithDuplicates() {
+ List<Integer> input = Arrays.asList(1, 2, 3, 2, 4, 5, 3);
+ List<Integer> expected = Arrays.asList(2, 3);
+ List<Integer> actual = ListUtils.findDuplicates(input);
+ assertEquals(expected, actual, "The list should contain only the
duplicate elements.");
+ }
+
+ @Test
+ public void testFindDuplicatesNoDuplicates() {
+ List<Integer> input = Arrays.asList(1, 2, 3, 4, 5);
+ List<Integer> expected = Arrays.asList();
+ List<Integer> actual = ListUtils.findDuplicates(input);
+ assertEquals(expected, actual, "The list should be empty as there are
no duplicates.");
+ }
+
+ @Test
+ public void testFindDuplicatesEmptyList() {
+ List<Integer> input = Arrays.asList();
+ List<Integer> expected = Arrays.asList();
+ List<Integer> actual = ListUtils.findDuplicates(input);
+ assertEquals(expected, actual, "The list should be empty as the input
list is empty.");
+ }
+
+ @Test
+ public void testFindDuplicatesSingleElement() {
+ List<Integer> input = Arrays.asList(1);
+ List<Integer> expected = Arrays.asList();
+ List<Integer> actual = ListUtils.findDuplicates(input);
+ assertEquals(expected, actual, "The list should be empty as there is
only one element.");
Review Comment:
Empty results can be simply asserted as
`assertTrue(ListUtils.duplicateSet(input).isEmpty());`
I'm going to create a CollectionUtils version of the method called
`duplicateSet`, I suggest the method be named the same here.
--
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]