You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/07/22 12:20:46 UTC
(commons-collections) branch master updated (7111a7007 -> 6c3bba1c2)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
from 7111a7007 Javadoc
new 7ad893360 Increase test coverage for ListUtils - isEqualList: same size, but different elements in the lists - isEqualList: same size, same elements, but different order - hashCodeForList: with null element - partition.get: edge cases (Exception) - union: multiple cases - sum: happy path
new 6c3bba1c2 Rename local variables to not hide the constants from lines 46, 47
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/commons/collections4/ListUtilsTest.java | 107 +++++++++++++++++----
1 file changed, 90 insertions(+), 17 deletions(-)
(commons-collections) 02/02: Rename local variables to not hide the constants from lines 46, 47
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
commit 6c3bba1c236caffb9eb5e5799d53cab01346f688
Author: Sigee <si...@gmail.com>
AuthorDate: Mon Jul 22 10:30:35 2024 +0200
Rename local variables to not hide the constants from lines 46, 47
---
.../apache/commons/collections4/ListUtilsTest.java | 52 +++++++++++-----------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java
index dcf02e825..4546ec874 100644
--- a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java
@@ -81,25 +81,25 @@ public class ListUtilsTest {
public void testEquals() {
final Collection<String> data = Arrays.asList("a", "b", "c");
- final List<String> a = new ArrayList<>( data );
- final List<String> b = new ArrayList<>( data );
-
- assertEquals(a, b);
- assertTrue(ListUtils.isEqualList(a, b));
- a.clear();
- assertFalse(ListUtils.isEqualList(a, b));
- assertFalse(ListUtils.isEqualList(a, null));
- assertFalse(ListUtils.isEqualList(null, b));
+ final List<String> list1 = new ArrayList<>( data );
+ final List<String> list2 = new ArrayList<>( data );
+
+ assertEquals(list1, list2);
+ assertTrue(ListUtils.isEqualList(list1, list2));
+ list1.clear();
+ assertFalse(ListUtils.isEqualList(list1, list2));
+ assertFalse(ListUtils.isEqualList(list1, null));
+ assertFalse(ListUtils.isEqualList(null, list2));
assertTrue(ListUtils.isEqualList(null, null));
- b.clear();
- a.add("a");
- b.add("b");
- assertFalse(ListUtils.isEqualList(a, b));
+ list2.clear();
+ list1.add("a");
+ list2.add("b");
+ assertFalse(ListUtils.isEqualList(list1, list2));
- a.add("b");
- b.add("a");
- assertFalse(ListUtils.isEqualList(a, b));
+ list1.add("b");
+ list2.add("a");
+ assertFalse(ListUtils.isEqualList(list1, list2));
}
@Test
@@ -120,19 +120,19 @@ public class ListUtilsTest {
public void testHashCode() {
final Collection<String> data = Arrays.asList("a", "b", "c");
- final List<String> a = new ArrayList<>(data);
- final List<String> b = new ArrayList<>(data);
+ final List<String> list1 = new ArrayList<>(data);
+ final List<String> list2 = new ArrayList<>(data);
- assertEquals(a.hashCode(), b.hashCode());
- assertEquals(a.hashCode(), ListUtils.hashCodeForList(a));
- assertEquals(b.hashCode(), ListUtils.hashCodeForList(b));
- assertEquals(ListUtils.hashCodeForList(a), ListUtils.hashCodeForList(b));
- a.clear();
- assertNotEquals(ListUtils.hashCodeForList(a), ListUtils.hashCodeForList(b));
+ assertEquals(list1.hashCode(), list2.hashCode());
+ assertEquals(list1.hashCode(), ListUtils.hashCodeForList(list1));
+ assertEquals(list2.hashCode(), ListUtils.hashCodeForList(list2));
+ assertEquals(ListUtils.hashCodeForList(list1), ListUtils.hashCodeForList(list2));
+ list1.clear();
+ assertNotEquals(ListUtils.hashCodeForList(list1), ListUtils.hashCodeForList(list2));
assertEquals(0, ListUtils.hashCodeForList(null));
- a.add(null);
- assertEquals(31, ListUtils.hashCodeForList(a));
+ list1.add(null);
+ assertEquals(31, ListUtils.hashCodeForList(list1));
}
/**
(commons-collections) 01/02: Increase test coverage for ListUtils - isEqualList: same size, but different elements in the lists - isEqualList: same size, same elements, but different order - hashCodeForList: with null element - partition.get: edge cases (Exception) - union: multiple cases - sum: happy path
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
commit 7ad893360d4889a5e10a2dd44ad14dfa72d2b47a
Author: Sigee <si...@gmail.com>
AuthorDate: Fri Jul 19 10:57:11 2024 +0200
Increase test coverage for ListUtils
- isEqualList: same size, but different elements in the lists
- isEqualList: same size, same elements, but different order
- hashCodeForList: with null element
- partition.get: edge cases (Exception)
- union: multiple cases
- sum: happy path
---
.../apache/commons/collections4/ListUtilsTest.java | 73 ++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java
index 44f8b1513..dcf02e825 100644
--- a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java
@@ -91,6 +91,15 @@ public class ListUtilsTest {
assertFalse(ListUtils.isEqualList(a, null));
assertFalse(ListUtils.isEqualList(null, b));
assertTrue(ListUtils.isEqualList(null, null));
+
+ b.clear();
+ a.add("a");
+ b.add("b");
+ assertFalse(ListUtils.isEqualList(a, b));
+
+ a.add("b");
+ b.add("a");
+ assertFalse(ListUtils.isEqualList(a, b));
}
@Test
@@ -121,6 +130,9 @@ public class ListUtilsTest {
a.clear();
assertNotEquals(ListUtils.hashCodeForList(a), ListUtils.hashCodeForList(b));
assertEquals(0, ListUtils.hashCodeForList(null));
+
+ a.add(null);
+ assertEquals(31, ListUtils.hashCodeForList(a));
}
/**
@@ -328,6 +340,12 @@ public class ListUtilsTest {
assertNotNull(partition);
assertEquals(3, partition.size());
assertEquals(1, partition.get(2).size());
+ assertAll(
+ () -> assertThrows(IndexOutOfBoundsException.class, () -> partition.get(-1),
+ "Index -1 must not be negative"),
+ () -> assertThrows(IndexOutOfBoundsException.class, () -> partition.get(3),
+ "Index " + 3 + " must be less than size " + partition.size())
+ );
assertAll(
() -> assertThrows(NullPointerException.class, () -> ListUtils.partition(null, 3),
"failed to check for null argument"),
@@ -481,4 +499,59 @@ public class ListUtilsTest {
assertEquals(expected, result);
}
+ @Test
+ public void testUnion() {
+ final List<String> list1 = new ArrayList<>();
+ list1.add(a);
+ final List<String> list2 = new ArrayList<>();
+ list2.add(b);
+ final List<String> result1 = ListUtils.union(list1, list2);
+ final List<String> expected1 = new ArrayList<>();
+ expected1.add(a);
+ expected1.add(b);
+ assertEquals(2, result1.size());
+ assertEquals(expected1, result1);
+
+ final List<String> list3 = new ArrayList<>();
+ list3.add(a);
+ final List<String> result2 = ListUtils.union(list1, list3);
+ final List<String> expected2 = new ArrayList<>();
+ expected2.add(a);
+ expected2.add(a);
+ assertEquals(2, result1.size());
+ assertEquals(expected2, result2);
+
+ list1.add(null);
+ final List<String> result3 = ListUtils.union(list1, list2);
+ final List<String> expected3 = new ArrayList<>();
+ expected3.add(a);
+ expected3.add(null);
+ expected3.add(b);
+ assertEquals(3, result3.size());
+ assertEquals(expected3, result3);
+
+ list2.add(null);
+ final List<String> result4 = ListUtils.union(list1, list2);
+ final List<String> expected4 = new ArrayList<>();
+ expected4.add(a);
+ expected4.add(null);
+ expected4.add(b);
+ expected4.add(null);
+ assertEquals(4, result4.size());
+ assertEquals(expected4, result4);
+ }
+
+ @Test
+ public void testSum() {
+ final List<String> list1 = new ArrayList<>();
+ list1.add(a);
+ final List<String> list2 = new ArrayList<>();
+ list2.add(b);
+ final List<String> expected1 = new ArrayList<>();
+ expected1.add(a);
+ expected1.add(b);
+ final List<String> result1 = ListUtils.sum(list1, list2);
+ assertEquals(2, result1.size());
+ assertEquals(expected1, result1);
+ }
}