From e5c95c28d268cd2103be68d306a38afa41926e17 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 31 Mar 2024 10:40:08 -0400 Subject: [PATCH] Rework test fixtures Next, grow the amount of data tested to find bugs in the tests with non-repeatable map ordering --- .../multimap/AbstractMultiValuedMapTest.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java index f305cbe21..1c931e10c 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java @@ -1235,21 +1235,30 @@ public abstract class AbstractMultiValuedMapTest extends AbstractObjectTes assumeTrue(isRemoveSupported()); resetFull(); final MultiValuedMap map = getMap(); - @SuppressWarnings("unchecked") - final Iterator it = map.get((K) "k0").iterator(); - while (it.hasNext()) { - it.next(); - it.remove(); + int expectedSize = map.size(); + final int maxK = getSampleKeySize(); + for (int k = 0; k < maxK; k++) { + final String key = makeKey(k); + final int cpk = getSampleCountPerKey(); + @SuppressWarnings("unchecked") + final Iterator it = map.get((K) key).iterator(); + while (it.hasNext()) { + it.next(); + it.remove(); + } + assertFalse(map.containsKey(key)); + for (int j = 0; j < cpk; j++) { + assertFalse(map.containsMapping(key, makeValue(k + 1, j))); + final Object value = makeValue(k, j); + assertFalse(map.containsMapping(key, value)); + assertFalse(map.containsValue(value)); + } + expectedSize -= cpk; + assertEquals(expectedSize, map.size()); + final Collection coll = map.remove("k0"); + assertNotNull(coll); + assertEquals(0, coll.size()); } - assertFalse(map.containsKey("k0")); - assertFalse(map.containsMapping("k0", "v1_1")); - assertFalse(map.containsMapping("k0", "v0_1")); - assertFalse(map.containsValue("v0_0")); - assertFalse(map.containsValue("v0_1")); - assertEquals(4, map.size()); - final Collection coll = map.remove("k0"); - assertNotNull(coll); - assertEquals(0, coll.size()); } @Test