From 8cae45185329a28d2f27bc96d6e7d94659f7b8c8 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 31 Mar 2024 10:26:47 -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 | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 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 38beefda5..1daf23195 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java @@ -1030,33 +1030,26 @@ public abstract class AbstractMultiValuedMapTest extends AbstractObjectTes public void testMultiValuedMapIterator() { final MultiValuedMap map = makeFullMap(); final MapIterator it = map.mapIterator(); - assertThrows(IllegalStateException.class, () -> it.getKey()); assertThrows(IllegalStateException.class, () -> it.getValue()); if (isAddSupported()) { assertThrows(IllegalStateException.class, () -> it.setValue((V) "V")); } - if (!isHashSetValue() && isAddSupported()) { - assertTrue(it.hasNext() ); - assertEquals("k0", it.next()); - assertEquals("k0", it.getKey()); - assertEquals("v0_0", it.getValue()); - assertEquals("k0", it.next()); - assertEquals("k0", it.getKey()); - assertEquals("v0_1", it.getValue()); - assertEquals("k1", it.next()); - assertEquals("k1", it.getKey()); - assertEquals("v1_0", it.getValue()); - assertEquals("k1", it.next()); - assertEquals("k1", it.getKey()); - assertEquals("v1_1", it.getValue()); - assertEquals("k2", it.next()); - assertEquals("k2", it.getKey()); - assertEquals("v2_0", it.getValue()); - assertEquals("k2", it.next()); - assertEquals("k2", it.getKey()); - assertEquals("v2_1", it.getValue()); + assertTrue(it.hasNext()); + final int maxK = getSampleKeySize(); + final int maxV = getSampleCountPerKey(); + for (int k = 0; k < maxK; k++) { + final Object key = makeKey(k); + for (int v = 0; v < maxV; v++) { + final Object value = makeValue(k, v); + assertTrue(it.hasNext()); + assertEquals(key, it.next()); + assertEquals(key, it.getKey()); + assertEquals(value, it.getValue()); + assertThrows(UnsupportedOperationException.class, () -> it.setValue((V) "threetrois")); + } + } assertThrows(UnsupportedOperationException.class, () -> it.setValue((V) "threetrois")); } }