From cce42dd86e4b4794671222c6c2d12fe57ae0ec57 Mon Sep 17 00:00:00 2001 From: "Craig P. Motlin" Date: Sun, 4 Aug 2024 13:51:33 -0400 Subject: [PATCH] Add tests Map_entrySet_setValue() and MutableMapIterable_entrySet_setValue(). --- .../map/mutable/ConcurrentHashMapTest.java | 17 ++++++++++++++ .../mutable/ConcurrentHashMapUnsafeTest.java | 22 +++++++++++++++++++ .../test/map/mutable/MapTestCase.java | 8 +++++++ .../mutable/MutableMapIterableTestCase.java | 8 +++++++ ...nmodifiableMutableMapIterableTestCase.java | 16 ++++++++++++++ 5 files changed, 71 insertions(+) diff --git a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/ConcurrentHashMapTest.java b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/ConcurrentHashMapTest.java index f8be53e7cc..bef09e7fe1 100644 --- a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/ConcurrentHashMapTest.java +++ b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/ConcurrentHashMapTest.java @@ -13,9 +13,12 @@ import java.util.Random; import org.eclipse.collections.api.map.MutableMap; +import org.eclipse.collections.api.map.MutableMapIterable; import org.eclipse.collections.impl.map.mutable.ConcurrentHashMap; +import static org.eclipse.collections.test.IterableTestCase.assertIterablesEqual; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; public class ConcurrentHashMapTest implements MutableMapTestCase @@ -55,4 +58,18 @@ public boolean supportsNullKeys() { return false; } + + @Override + public void Map_entrySet_setValue() + { + MutableMapIterable map = this.newWithKeysValues("3", 3, "2", 2, "1", 1); + map.entrySet().forEach(each -> assertThrows(UnsupportedOperationException.class, () -> each.setValue(each.getValue() + 1))); + assertIterablesEqual(this.newWithKeysValues("3", 3, "2", 2, "1", 1), map); + } + + @Override + public void MutableMapIterable_entrySet_setValue() + { + this.Map_entrySet_setValue(); + } } diff --git a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/ConcurrentHashMapUnsafeTest.java b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/ConcurrentHashMapUnsafeTest.java index 163b1e2ee9..576dd80594 100644 --- a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/ConcurrentHashMapUnsafeTest.java +++ b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/ConcurrentHashMapUnsafeTest.java @@ -13,9 +13,13 @@ import java.util.Random; import org.eclipse.collections.api.map.MutableMap; +import org.eclipse.collections.api.map.MutableMapIterable; import org.eclipse.collections.impl.map.mutable.ConcurrentHashMapUnsafe; +import org.junit.jupiter.api.Test; +import static org.eclipse.collections.test.IterableTestCase.*; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; public class ConcurrentHashMapUnsafeTest implements MutableMapTestCase @@ -55,4 +59,22 @@ public boolean supportsNullKeys() { return false; } + + @Override + @Test + public void Map_entrySet_setValue() + { + MutableMapIterable map = this.newWithKeysValues("3", 3, "2", 2, "1", 1); + map.entrySet().forEach(each -> assertThrows(RuntimeException.class, () -> each.setValue(each.getValue() + 1))); + assertIterablesEqual(this.newWithKeysValues("3", 3, "2", 2, "1", 1), map); + } + + @Override + @Test + public void MutableMapIterable_entrySet_setValue() + { + MutableMapIterable map = this.newWithKeysValues("3", 3, "2", 2, "1", 1); + map.entrySet().forEach(each -> assertThrows(RuntimeException.class, () -> each.setValue(each.getValue() + 1))); + assertIterablesEqual(this.newWithKeysValues("3", 3, "2", 2, "1", 1), map); + } } diff --git a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/MapTestCase.java b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/MapTestCase.java index d8fb5f2ad6..8ed860c929 100644 --- a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/MapTestCase.java +++ b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/MapTestCase.java @@ -114,6 +114,14 @@ default void Map_entrySet_remove() } } + @Test + default void Map_entrySet_setValue() + { + Map map = this.newWithKeysValues("3", 3, "2", 2, "1", 1); + map.entrySet().forEach(each -> each.setValue(each.getValue() + 1)); + assertIterablesEqual(this.newWithKeysValues("3", 4, "2", 3, "1", 2), map); + } + @Test default void Map_put() { diff --git a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/MutableMapIterableTestCase.java b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/MutableMapIterableTestCase.java index dc99514ef4..4c7038d849 100644 --- a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/MutableMapIterableTestCase.java +++ b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/MutableMapIterableTestCase.java @@ -214,4 +214,12 @@ default void MutableMapIterable_updateValue() Collections.nCopies(1000, 2), map4.values()); } + + @Test + default void MutableMapIterable_entrySet_setValue() + { + MutableMapIterable map = this.newWithKeysValues("3", 3, "2", 2, "1", 1); + map.entrySet().forEach(each -> each.setValue(each.getValue() + 1)); + assertIterablesEqual(this.newWithKeysValues("3", 4, "2", 3, "1", 2), map); + } } diff --git a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/UnmodifiableMutableMapIterableTestCase.java b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/UnmodifiableMutableMapIterableTestCase.java index 650a1c2909..6bbe06ba80 100644 --- a/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/UnmodifiableMutableMapIterableTestCase.java +++ b/unit-tests-java8/src/test/java/org/eclipse/collections/test/map/mutable/UnmodifiableMutableMapIterableTestCase.java @@ -190,4 +190,20 @@ default void Map_merge() })); assertEquals(this.newWithKeysValues(1, "1", 2, "2", 3, "3"), map); } + + @Override + @Test + default void Map_entrySet_setValue() + { + Map map = this.newWithKeysValues("3", 3, "2", 2, "1", 1); + map.entrySet().forEach(each -> assertThrows(UnsupportedOperationException.class, () -> each.setValue(each.getValue() + 1))); + assertIterablesEqual(this.newWithKeysValues("3", 3, "2", 2, "1", 1), map); + } + + @Override + @Test + default void MutableMapIterable_entrySet_setValue() + { + this.Map_entrySet_setValue(); + } }