Skip to content

Commit

Permalink
[COMPRESS-872] Add MultiKeyMapTest.testCompress872()
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Dec 8, 2024
1 parent bdb26ce commit bcd7973
Showing 1 changed file with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
* <p>
* Claim:
* </p>
* <ol>
* <li>Create a MultiKeyMap, with key(s) of a type (class/record) which has some fields.
* <li>Use multiKeyMap.put(T... keys, V value), to create an entry in the Map, to map the keys to a value
* <li>Use multiKeyMap.get(T... keys), to verify that the mapping exists and returns the expected value.
* <li>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.
* <li>Use multiKeyMap.get(T... keys) again, however, now there is no mapping for these keys!
* <li>Use multiKeyMap.get(T... keys) with the new modified/altered objects, and it will return the expected value
* </ol>
*/
@Test
public void testCompress872() {
final AtomicReference<String> k1 = new AtomicReference<>("K1v1");
final AtomicReference<String> k2 = new AtomicReference<>("K2v1");
final MultiKeyMap<AtomicReference<String>, String> map = (MultiKeyMap<AtomicReference<String>, 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() {
Expand Down Expand Up @@ -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();
Expand All @@ -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() {
Expand All @@ -480,4 +507,5 @@ public void testNullHandling() {

assertThrows(NullPointerException.class, () -> map.put(null, (V) new Object()));
}

}

0 comments on commit bcd7973

Please sign in to comment.