This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-collections.git
commit 6742fee39960967a679468e118e4185dbc9aeb2a Author: Gary Gregory <[email protected]> AuthorDate: Fri Jun 19 13:02:05 2026 +0000 Refactor tests for PR copy-pasta. --- .../commons/collections4/list/SetUniqueListTest.java | 15 ++------------- .../commons/collections4/map/ListOrderedMapTest.java | 14 +------------- .../commons/collections4/set/ListOrderedSetTest.java | 14 +------------- 3 files changed, 4 insertions(+), 39 deletions(-) diff --git a/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java b/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java index d03ac8a3e..8232646bd 100644 --- a/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java @@ -22,11 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -113,15 +109,8 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> { list.add("beta"); // push a duplicate straight onto the decorated list, bypassing the uniqueness set list.decorated().add("alpha"); - final ByteArrayOutputStream out = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(out)) { - oos.writeObject(list); - } - assertThrows(InvalidObjectException.class, () -> { - try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()))) { - ois.readObject(); - } - }); + assertThrows(InvalidObjectException.class, () -> serializeDeserialize(list)); + } @Test diff --git a/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java b/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java index 9b35f81df..699b756e1 100644 --- a/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java @@ -21,11 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -178,15 +174,7 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> { map.put("two", "2"); // drop a key straight from the backing map; the insert-order list still names it map.decorated().remove("one"); - final ByteArrayOutputStream out = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(out)) { - oos.writeObject(map); - } - assertThrows(InvalidObjectException.class, () -> { - try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()))) { - ois.readObject(); - } - }); + assertThrows(InvalidObjectException.class, () -> serializeDeserialize(map)); } @Test diff --git a/src/test/java/org/apache/commons/collections4/set/ListOrderedSetTest.java b/src/test/java/org/apache/commons/collections4/set/ListOrderedSetTest.java index c08b1bb8d..7794af1bd 100644 --- a/src/test/java/org/apache/commons/collections4/set/ListOrderedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/ListOrderedSetTest.java @@ -21,11 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -104,15 +100,7 @@ public class ListOrderedSetTest<E> set.add("green"); // remove an element from the decorated set only; the order list keeps naming it set.decorated().remove("red"); - final ByteArrayOutputStream out = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(out)) { - oos.writeObject(set); - } - assertThrows(InvalidObjectException.class, () -> { - try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()))) { - ois.readObject(); - } - }); + assertThrows(InvalidObjectException.class, () -> serializeDeserialize(set)); } @Test
