You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/09/25 12:45:13 UTC
(commons-collections) branch master updated: Add AbstractMapTest.testReplaceKeyValueValue()
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
The following commit(s) were added to refs/heads/master by this push:
new f4f3e36a1 Add AbstractMapTest.testReplaceKeyValueValue()
f4f3e36a1 is described below
commit f4f3e36a12438c7bbadae711fbebd27ace464ca7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 25 08:45:03 2024 -0400
Add AbstractMapTest.testReplaceKeyValueValue()
---
.../commons/collections4/map/AbstractMapTest.java | 46 +++++++++++++++++++++-
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java
index 3ea96bcaa..4e8bce114 100644
--- a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java
@@ -1853,8 +1853,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
oldValue = getMap().get(sampleKey);
assertEquals(oldValue, getMap().replace(sampleKey, value), messageSupplier);
if (isAllowNullValue()) {
- final V expected = getMap().get(sampleKey);
- assertEquals(expected, getMap().replace(sampleKey, null), messageSupplier);
+ oldValue = getMap().get(sampleKey);
+ assertEquals(oldValue, getMap().replace(sampleKey, null), messageSupplier);
assertNull(getMap().get(sampleKey), messageSupplier);
assertNull(getMap().replace(sampleKey, null), messageSupplier);
assertNull(getMap().replace(sampleKey, value), messageSupplier);
@@ -1862,6 +1862,48 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
}
}
+ /**
+ * Tests {@link Map#replace(Object, Object, Object)}.
+ */
+ @Test
+ public void testReplaceKeyValueValue() {
+ assumeTrue(isRemoveSupported());
+ resetFull();
+ final K[] sampleKeys = getSampleKeys();
+ final V[] sampleValues = getSampleValues();
+ final V[] newValues = getNewSampleValues();
+ assertFalse(getMap().isEmpty());
+ for (final AtomicInteger inc = new AtomicInteger(); inc.get() < sampleKeys.length; inc.incrementAndGet()) {
+ final int i = inc.get();
+ final V value = sampleValues[i];
+ final K key = sampleKeys[i];
+ final Supplier<String> messageSupplier = () -> String.format("[%,d] key '%s', value '%s'; %s", inc.get(), key, value, getMap());
+ boolean containsKey = getMap().containsKey(key);
+ assertEquals(containsKey, getMap().replace(key, value, value), messageSupplier);
+ containsKey = getMap().containsKey(key);
+ assertEquals(containsKey, getMap().replace(key, value, value), messageSupplier);
+ final V newValue = newValues[i];
+ containsKey = getMap().containsKey(key);
+ assertEquals(containsKey, getMap().replace(key, value, newValue), messageSupplier);
+ V oldValue = getMap().get(key);
+ containsKey = getMap().containsKey(key);
+ assertEquals(containsKey, getMap().replace(key, oldValue, newValue), messageSupplier);
+ oldValue = getMap().get(key);
+ containsKey = getMap().containsKey(key);
+ assertEquals(containsKey, getMap().replace(key, oldValue, value), messageSupplier);
+ if (isAllowNullValue()) {
+ oldValue = getMap().get(key);
+ containsKey = getMap().containsKey(key);
+ assertEquals(containsKey, getMap().replace(key, oldValue, null), messageSupplier);
+ assertNull(getMap().get(key), messageSupplier);
+ containsKey = getMap().containsKey(key);
+ assertEquals(containsKey, getMap().replace(key, null, null), messageSupplier);
+ containsKey = getMap().containsKey(key);
+ assertEquals(containsKey, getMap().replace(key, null, value), messageSupplier);
+ }
+ }
+ }
+
/**
* Test to ensure the test setup is working properly. This method checks to ensure that the getSampleKeys and getSampleValues methods are returning results
* that look appropriate. That is, they both return a non-null array of equal length. The keys array must not have any duplicate values, and may only