Skip to content

Commit

Permalink
Add tests Map_entrySet_setValue() and MutableMapIterable_entrySet_set…
Browse files Browse the repository at this point in the history
…Value().
  • Loading branch information
motlin committed Sep 28, 2024
1 parent bc0cf82 commit cce42dd
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,4 +58,18 @@ public boolean supportsNullKeys()
{
return false;
}

@Override
public void Map_entrySet_setValue()
{
MutableMapIterable<String, Integer> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,4 +59,22 @@ public boolean supportsNullKeys()
{
return false;
}

@Override
@Test
public void Map_entrySet_setValue()
{
MutableMapIterable<String, Integer> 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<String, Integer> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ default void Map_entrySet_remove()
}
}

@Test
default void Map_entrySet_setValue()
{
Map<String, Integer> 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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,12 @@ default void MutableMapIterable_updateValue()
Collections.nCopies(1000, 2),
map4.values());
}

@Test
default void MutableMapIterable_entrySet_setValue()
{
MutableMapIterable<String, Integer> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Integer> 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();
}
}

0 comments on commit cce42dd

Please sign in to comment.