You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2020/04/18 23:37:57 UTC

[commons-collections] branch master updated (6b1e2eb -> 30f48c3)

This is an automated email from the ASF dual-hosted git repository.

kinow pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git.


    from 6b1e2eb  Add openjdk14 to Travis.
     new 9beb1e0  [COLLECTIONS-760]: Add tests for MapUtils.
     new e3aa762  [COLLECTIONS-760]: add changelog
     new 30f48c3  Merge branch 'pr-149'

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |   3 +
 .../apache/commons/collections4/MapUtilsTest.java  | 111 +++++++++++++++++++--
 2 files changed, 108 insertions(+), 6 deletions(-)


[commons-collections] 02/03: [COLLECTIONS-760]: add changelog

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git

commit e3aa7625b3914b17b091044847260c8a81ea8135
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Sun Apr 19 11:36:35 2020 +1200

    [COLLECTIONS-760]: add changelog
---
 src/changes/changes.xml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b5fb985..ee57d56 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -21,6 +21,9 @@
   </properties>
   <body>
   <release version="4.5" date="2020-MM-DD" description="Maintenance release.">
+    <action issue="COLLECTIONS-760" dev="kinow" type="add" due-to="Isira Seneviratne">
+      Add tests for MapUtils
+    </action>
     <action issue="COLLECTIONS-737" dev="kinow" type="update" due-to="Prodigysov">
       Return 0 immediately if the given iterable is null in IterableUtils#size. Update tests.
     </action>


[commons-collections] 03/03: Merge branch 'pr-149'

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git

commit 30f48c3d1d89937b03d1ec84544ee14ecb77b90f
Merge: 6b1e2eb e3aa762
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Sun Apr 19 11:37:22 2020 +1200

    Merge branch 'pr-149'
    
    This closes #149

 src/changes/changes.xml                            |   3 +
 .../apache/commons/collections4/MapUtilsTest.java  | 111 +++++++++++++++++++--
 2 files changed, 108 insertions(+), 6 deletions(-)


[commons-collections] 01/03: [COLLECTIONS-760]: Add tests for MapUtils.

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git

commit 9beb1e0b115cb56b02a3baee4fdb2cdee2bdddb2
Author: Isira Seneviratne <is...@gmail.com>
AuthorDate: Sat Apr 18 17:29:54 2020 +0530

    [COLLECTIONS-760]: Add tests for MapUtils.
---
 .../apache/commons/collections4/MapUtilsTest.java  | 111 +++++++++++++++++++--
 1 file changed, 105 insertions(+), 6 deletions(-)

diff --git a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java
index c131fa5..2e2f806 100644
--- a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java
@@ -28,6 +28,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
+import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -40,6 +41,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.ResourceBundle;
 import java.util.Set;
+import java.util.SortedMap;
 import java.util.TreeMap;
 import org.apache.commons.collections4.collection.TransformedCollectionTest;
 import org.apache.commons.collections4.junit.AbstractAvailableLocalesTest;
@@ -56,6 +58,7 @@ import org.junit.Test;
  */
 @SuppressWarnings("boxing")
 public class MapUtilsTest extends AbstractAvailableLocalesTest {
+    private static final String THREE = "Three";
 
     public MapUtilsTest(final Locale locale) {
         super(locale);
@@ -892,6 +895,45 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
     }
 
     @Test
+    public void testLazyMap() {
+        final Map<String, Integer> lazyMap = MapUtils.lazyMap(new HashMap<>(), () -> 1);
+        lazyMap.put("Two", 2);
+
+        assertEquals(Integer.valueOf(2), lazyMap.get("Two"));
+        assertEquals(Integer.valueOf(1), lazyMap.get(THREE));
+    }
+
+    @Test
+    public void testLazySortedMapFactory() {
+        final SortedMap<String, Integer> lazySortedMap = MapUtils.lazySortedMap(new TreeMap<>(), () -> 1);
+        lazySortedMap.put("Two", 2);
+
+        assertEquals(Integer.valueOf(2), lazySortedMap.get("Two"));
+        assertEquals(Integer.valueOf(1), lazySortedMap.get(THREE));
+
+        final Set<Map.Entry<String, Integer>> entrySet = new HashSet<>();
+        entrySet.add(new AbstractMap.SimpleEntry<>(THREE, 1));
+        entrySet.add(new AbstractMap.SimpleEntry<>("Two", 2));
+
+        assertEquals(entrySet, lazySortedMap.entrySet());
+    }
+
+    @Test
+    public void testLazySortedMapTransformer() {
+        final SortedMap<String, Integer> lazySortedMap = MapUtils.lazySortedMap(new TreeMap<>(), s -> 1);
+        lazySortedMap.put("Two", 2);
+
+        assertEquals(Integer.valueOf(2), lazySortedMap.get("Two"));
+        assertEquals(Integer.valueOf(1), lazySortedMap.get(THREE));
+
+        final Set<Map.Entry<String, Integer>> entrySet = new HashSet<>();
+        entrySet.add(new AbstractMap.SimpleEntry<>(THREE, 1));
+        entrySet.add(new AbstractMap.SimpleEntry<>("Two", 2));
+
+        assertEquals(entrySet, lazySortedMap.entrySet());
+    }
+
+    @Test
     public void testSize0() {
         assertEquals(0, MapUtils.size(new HashMap<>()));
     }
@@ -932,6 +974,62 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
     }
 
     @Test
+    public void testTransformedMap() {
+        final Map<Long, Long> map = new HashMap<>();
+
+        final Map<Long, Long> transformedMap = MapUtils.transformedMap(map, i -> i + 1, i -> i + 10);
+        transformedMap.put(1L, 100L);
+
+        final Set<Map.Entry<Long, Long>> entrySet = new HashSet<>();
+        entrySet.add(new AbstractMap.SimpleEntry<>(2L, 110L));
+
+        assertEquals(entrySet, transformedMap.entrySet());
+    }
+
+    @Test
+    public void testTransformedSortedMap() {
+        final SortedMap<Long, Long> sortedMap = new TreeMap<>();
+
+        final SortedMap<Long, Long> transformedSortedMap = MapUtils.transformedSortedMap(sortedMap, i -> i + 1, i -> i + 10);
+        transformedSortedMap.put(2L, 200L);
+        transformedSortedMap.put(1L, 100L);
+
+        final Set<Map.Entry<Long, Long>> entrySet = new HashSet<>();
+        entrySet.add(new AbstractMap.SimpleEntry<>(2L, 110L));
+        entrySet.add(new AbstractMap.SimpleEntry<>(3L, 210L));
+
+        assertEquals(entrySet, transformedSortedMap.entrySet());
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testUnmodifiableMap() {
+        MapUtils.unmodifiableMap(new HashMap<>()).clear();
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testUnmodifiableSortedMap() {
+        MapUtils.unmodifiableSortedMap(new TreeMap<>()).clear();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testFixedSizeMap() {
+        MapUtils.fixedSizeMap(new HashMap<>()).put(new Object(), new Object());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testFixedSizeSortedMap() {
+        MapUtils.fixedSizeSortedMap(new TreeMap<Long, Long>()).put(1L, 1L);
+    }
+
+    @Test
+    public void testGetNumberValueWithInvalidString() {
+        final Map<String, String> map = new HashMap<>();
+        map.put("key", "one");
+
+        assertNull(MapUtils.getNumber(map, "key"));
+    }
+
+    @Test
     public void testgetDoubleValue() {
         final Map<String, Double> in = new HashMap<>();
         in.put("key", 2.0);
@@ -992,15 +1090,16 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
         assertEquals(2.0, MapUtils.getLongValue(in, "key", 0L), 0);
         assertEquals(2.0, MapUtils.getLongValue(in, "key"), 0);
         assertEquals(1, MapUtils.getLongValue(in, "noKey", 1L), 0);
-        assertEquals(1, MapUtils.getLongValue(in, "noKey", key -> {
-            return 1L;
-        }), 0);
+        assertEquals(1, MapUtils.getLongValue(in, "noKey", key -> 1L), 0);
         assertEquals(0, MapUtils.getLongValue(in, "noKey"), 0);
         assertEquals(2.0, MapUtils.getLong(in, "key", 0L), 0);
         assertEquals(1, MapUtils.getLong(in, "noKey", 1L), 0);
-        assertEquals(1, MapUtils.getLong(in, "noKey", key -> {
-            return 1L;
-        }), 0);
+        assertEquals(1, MapUtils.getLong(in, "noKey", key -> 1L), 0);
+
+        final Map<String, Number> in1 = new HashMap<>();
+        in1.put("key", 2);
+
+        assertEquals(Long.valueOf(2), MapUtils.getLong(in1, "key"));
 
         final Map<String, String> inStr = new HashMap<>();
         inStr.put("str1", "2");