commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1461601 - in /commons/proper/chain/trunk/core/src: main/java/org/apache/commons/chain2/impl/CatalogBase.java test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java
Date Wed, 27 Mar 2013 14:23:12 GMT
Author: simonetripodi
Date: Wed Mar 27 14:23:12 2013
New Revision: 1461601

URL: http://svn.apache.org/r1461601
Log:
[CHAIN-80] NPE when submitting null commands map to CatalogBase - patch submitted by Steve
Westwood

Modified:
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/CatalogBase.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java

Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/CatalogBase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/CatalogBase.java?rev=1461601&r1=1461600&r2=1461601&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/CatalogBase.java
(original)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/CatalogBase.java
Wed Mar 27 14:23:12 2013
@@ -58,10 +58,16 @@ public class CatalogBase<K, V, C extends
      * All Map keys should be <code>String</code> and all values should be <code>Command</code>.</p>
      *
      * @param commands Map of Commands.
+     * 
+     * @exception IllegalArgumentException if <code>commands</code> 
+     * is <code>null</code>
      *
      * @since Chain 1.1
      */
-    public CatalogBase(Map<String, Command<K, V, C>> commands ) {
+    public CatalogBase(Map<String, Command<K, V, C>> commands) {
+        if (commands == null) {
+            throw new IllegalArgumentException("'commands' parameter must be not null");
+        }
         this.commands.putAll( commands );
     }
 

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java?rev=1461601&r1=1461600&r2=1461601&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java
Wed Mar 27 14:23:12 2013
@@ -19,9 +19,10 @@ package org.apache.commons.chain2.impl;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 
 import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.commons.chain2.Catalog;
 import org.apache.commons.chain2.Command;
@@ -145,7 +146,31 @@ public class CatalogBaseTestCase {
         assertNull(catalog.getCommand("ChainBase"));
     }
 
-
+    // Test construction with commands collection
+    @Test
+    public void testInstantiationWithMapOfCommands() {
+        @SuppressWarnings("serial")
+        Map<String, Command<String, Object, Context<String, Object>>> 
+            commands = new ConcurrentHashMap<String, Command<String, Object, Context<String,
Object>>>() {
+            {
+                put("AddingCommand", new AddingCommand("", null));
+            }
+        };
+
+        CatalogBase<String, Object, Context<String, Object>> 
+            catalog = new CatalogBase<String, Object, Context<String, Object>>(commands);
+
+        assertEquals("Correct command count", 1, catalog.getCommands().size());
+    }
+
+    // Examine construction with null commands collection
+    @Test(expected = IllegalArgumentException.class)
+    public void testInstantiationWithNullMapOfCommands() {
+        Map<String, Command<String, Object, Context<String, Object>>> commands
= null;
+        @SuppressWarnings("unused")
+        CatalogBase<String, Object, Context<String, Object>> 
+            catalog = new CatalogBase<String, Object, Context<String, Object>>(commands);
+    }
 
 
     // -------------------------------------------------------- Support Methods



Mime
View raw message