From eab18e9851b46f9e3778c414155acccf5d775823 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 31 Mar 2024 10:54:20 -0400 Subject: [PATCH] Rework test fixtures Next, grow the amount of data tested to find bugs in the tests with non-repeatable map ordering --- .../UnmodifiableMultiValuedMapTest.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/apache/commons/collections4/multimap/UnmodifiableMultiValuedMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/UnmodifiableMultiValuedMapTest.java index efa0c651f..cbd8c2f2d 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/UnmodifiableMultiValuedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/UnmodifiableMultiValuedMapTest.java @@ -21,10 +21,13 @@ 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.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -52,9 +55,21 @@ public class UnmodifiableMultiValuedMapTest extends AbstractMultiValuedMap * @param map the MultiValuedMap to check */ private void assertMapContainsAllValues(final MultiValuedMap map) { - assertEquals("[v0_0, v0_1]", map.get((K) "k0").toString()); - assertEquals("[v1_0, v1_1]", map.get((K) "k1").toString()); - assertEquals("[v2_0, v2_1]", map.get((K) "k2").toString()); + final int maxK = getSampleKeySize(); + final int cpk = getSampleCountPerKey(); + for (int k = 0; k < maxK; k++) { + final K key = makeKey(k); + final Collection collection = map.get((K) key); + assertEquals(cpk, collection.size()); + final String toString = collection.toString(); + final List expected = new ArrayList<>(cpk); + for (int j = 0; j < cpk; j++) { + expected.add(makeValue(k, j)); + } + assertEquals(expected.size(), collection.size()); + assertEquals(expected, new ArrayList<>(collection)); + assertEquals(expected.toString(), toString); + } } @Override