You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/04/26 11:50:48 UTC

[GitHub] [commons-collections] dota17 commented on a change in pull request #126: Improve MapUtils with the null checks, add JUnit for it and add Javadoc for the parameter indent.

dota17 commented on a change in pull request #126:
URL: https://github.com/apache/commons-collections/pull/126#discussion_r415291561



##########
File path: src/test/java/org/apache/commons/collections4/MapUtilsTest.java
##########
@@ -146,19 +147,36 @@ public void testInvertMap() {
         final Set<String> inKeySet = new HashSet<>(in.keySet());
         final Set<String> inValSet = new HashSet<>(in.values());
 
-        final Map<String, String> out =  MapUtils.invertMap(in);
+        final Map<String, String> out = MapUtils.invertMap(in);
 
         final Set<String> outKeySet = new HashSet<>(out.keySet());
         final Set<String> outValSet = new HashSet<>(out.values());
 
         assertEquals(inKeySet, outValSet);
         assertEquals(inValSet, outKeySet);
 
-        assertEquals( "1", out.get("A"));
-        assertEquals( "2", out.get("B"));
-        assertEquals( "3", out.get("C"));
-        assertEquals( "4", out.get("D"));
-        assertEquals( "5", out.get("E"));
+        assertEquals("1", out.get("A"));
+        assertEquals("2", out.get("B"));
+        assertEquals("3", out.get("C"));
+        assertEquals("4", out.get("D"));
+        assertEquals("5", out.get("E"));
+    }
+
+    @Test
+    public void testInvertEmptyMap() {
+        Map<String, String> emptyMap = new HashMap<>();
+        Map<String, String> resultMap = MapUtils.invertMap(emptyMap);
+        assertEquals(emptyMap, resultMap);
+    }
+
+    @Test
+    public void testInvertMapNull() {
+        try {
+            MapUtils.invertMap(null);
+            fail("Expecting NullPointerException for null map");
+        } catch (final NullPointerException ex) {
+            // expected
+        }

Review comment:
       > Now that we depend on JUnit 5, you can/should test exceptions the with JUnit 5 APIs: https://junit.org/junit5/docs/current/user-guide/#writing-tests-assertions
   
   It's my pleasure to finish it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org