Skip to content

Commit bcd7973

Browse files
committed
[COMPRESS-872] Add MultiKeyMapTest.testCompress872()
1 parent bdb26ce commit bcd7973

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

src/test/java/org/apache/commons/collections4/map/MultiKeyMapTest.java

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.junit.jupiter.api.Assertions.fail;
2626

2727
import java.util.Map;
28+
import java.util.concurrent.atomic.AtomicReference;
2829

2930
import org.apache.commons.collections4.MapIterator;
3031
import org.apache.commons.collections4.keyvalue.MultiKey;
@@ -136,6 +137,32 @@ public void testClone() {
136137
assertSame(map.get(new MultiKey<>((K) I1, (K) I2)), cloned.get(new MultiKey<>((K) I1, (K) I2)));
137138
}
138139

140+
/**
141+
* Tests COMPRESS-872
142+
* <p>
143+
* Claim:
144+
* </p>
145+
* <ol>
146+
* <li>Create a MultiKeyMap, with key(s) of a type (class/record) which has some fields.
147+
* <li>Use multiKeyMap.put(T... keys, V value), to create an entry in the Map, to map the keys to a value
148+
* <li>Use multiKeyMap.get(T... keys), to verify that the mapping exists and returns the expected value.
149+
* <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.
150+
* <li>Use multiKeyMap.get(T... keys) again, however, now there is no mapping for these keys!
151+
* <li>Use multiKeyMap.get(T... keys) with the new modified/altered objects, and it will return the expected value
152+
* </ol>
153+
*/
154+
@Test
155+
public void testCompress872() {
156+
final AtomicReference<String> k1 = new AtomicReference<>("K1v1");
157+
final AtomicReference<String> k2 = new AtomicReference<>("K2v1");
158+
final MultiKeyMap<AtomicReference<String>, String> map = (MultiKeyMap<AtomicReference<String>, String>) makeObject();
159+
assertNull(map.put(k1, k2, "V"));
160+
assertEquals("V", map.get(k1, k2));
161+
k1.set("K1v2");
162+
assertEquals("V", map.get(k1, k2));
163+
assertEquals("V", map.get(k1, k2));
164+
}
165+
139166
@Test
140167
@SuppressWarnings("unchecked")
141168
public void testLRUMultiKeyMap() {
@@ -437,6 +464,17 @@ public void testMultiKeyRemoveAll3() {
437464
}
438465
}
439466

467+
// public void testCreate() throws Exception {
468+
// resetEmpty();
469+
// writeExternalFormToDisk(
470+
// (java.io.Serializable) map,
471+
// "src/test/resources/data/test/MultiKeyMap.emptyCollection.version4.obj");
472+
// resetFull();
473+
// writeExternalFormToDisk(
474+
// (java.io.Serializable) map,
475+
// "src/test/resources/data/test/MultiKeyMap.fullCollection.version4.obj");
476+
// }
477+
440478
@Test
441479
public void testMultiKeyRemoveAll4() {
442480
resetFull();
@@ -451,17 +489,6 @@ public void testMultiKeyRemoveAll4() {
451489
}
452490
}
453491

454-
// public void testCreate() throws Exception {
455-
// resetEmpty();
456-
// writeExternalFormToDisk(
457-
// (java.io.Serializable) map,
458-
// "src/test/resources/data/test/MultiKeyMap.emptyCollection.version4.obj");
459-
// resetFull();
460-
// writeExternalFormToDisk(
461-
// (java.io.Serializable) map,
462-
// "src/test/resources/data/test/MultiKeyMap.fullCollection.version4.obj");
463-
// }
464-
465492
@Test
466493
@SuppressWarnings("unchecked")
467494
public void testNullHandling() {
@@ -480,4 +507,5 @@ public void testNullHandling() {
480507

481508
assertThrows(NullPointerException.class, () -> map.put(null, (V) new Object()));
482509
}
510+
483511
}

0 commit comments

Comments
 (0)