diff --git a/src/test/java/org/apache/commons/collections4/map/MultiKeyMapTest.java b/src/test/java/org/apache/commons/collections4/map/MultiKeyMapTest.java index 73fc659338..456269a275 100644 --- a/src/test/java/org/apache/commons/collections4/map/MultiKeyMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/MultiKeyMapTest.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.fail; import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.collections4.MapIterator; import org.apache.commons.collections4.keyvalue.MultiKey; @@ -136,6 +137,32 @@ public void testClone() { assertSame(map.get(new MultiKey<>((K) I1, (K) I2)), cloned.get(new MultiKey<>((K) I1, (K) I2))); } + /** + * Tests COMPRESS-872 + *

+ * Claim: + *

+ *
    + *
  1. Create a MultiKeyMap, with key(s) of a type (class/record) which has some fields. + *
  2. Use multiKeyMap.put(T... keys, V value), to create an entry in the Map, to map the keys to a value + *
  3. Use multiKeyMap.get(T... keys), to verify that the mapping exists and returns the expected value. + *
  4. Modify/alter any of the objects used as a key. It is enough to change the value of any member field of any of the objects. + *
  5. Use multiKeyMap.get(T... keys) again, however, now there is no mapping for these keys! + *
  6. Use multiKeyMap.get(T... keys) with the new modified/altered objects, and it will return the expected value + *
+ */ + @Test + public void testCompress872() { + final AtomicReference k1 = new AtomicReference<>("K1v1"); + final AtomicReference k2 = new AtomicReference<>("K2v1"); + final MultiKeyMap, String> map = (MultiKeyMap, String>) makeObject(); + assertNull(map.put(k1, k2, "V")); + assertEquals("V", map.get(k1, k2)); + k1.set("K1v2"); + assertEquals("V", map.get(k1, k2)); + assertEquals("V", map.get(k1, k2)); + } + @Test @SuppressWarnings("unchecked") public void testLRUMultiKeyMap() { @@ -437,6 +464,17 @@ public void testMultiKeyRemoveAll3() { } } +// public void testCreate() throws Exception { +// resetEmpty(); +// writeExternalFormToDisk( +// (java.io.Serializable) map, +// "src/test/resources/data/test/MultiKeyMap.emptyCollection.version4.obj"); +// resetFull(); +// writeExternalFormToDisk( +// (java.io.Serializable) map, +// "src/test/resources/data/test/MultiKeyMap.fullCollection.version4.obj"); +// } + @Test public void testMultiKeyRemoveAll4() { resetFull(); @@ -451,17 +489,6 @@ public void testMultiKeyRemoveAll4() { } } -// public void testCreate() throws Exception { -// resetEmpty(); -// writeExternalFormToDisk( -// (java.io.Serializable) map, -// "src/test/resources/data/test/MultiKeyMap.emptyCollection.version4.obj"); -// resetFull(); -// writeExternalFormToDisk( -// (java.io.Serializable) map, -// "src/test/resources/data/test/MultiKeyMap.fullCollection.version4.obj"); -// } - @Test @SuppressWarnings("unchecked") public void testNullHandling() { @@ -480,4 +507,5 @@ public void testNullHandling() { assertThrows(NullPointerException.class, () -> map.put(null, (V) new Object())); } + }