Bug 5444: Allow null value in config module list setter 33/37433/3
authorAndrej Mak <andmak@cisco.com>
Mon, 11 Apr 2016 11:17:54 +0000 (13:17 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 19 Apr 2016 14:26:40 +0000 (14:26 +0000)
Change-Id: Ibdd8f93d7d8bf213892c1af8632f3ec0989cd617
Signed-off-by: Andrej Mak <andmak@cisco.com>
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java
opendaylight/config/yang-test/src/test/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleTest.java

index 999b27f..4c67a67 100644 (file)
@@ -690,8 +690,8 @@ public class TemplateFactory {
 
                 String setterBody = "this." + varName + " = " + varName + ";";
                 if (isListOfDependencies) {
-                    String nullCheck = String.format("if (%s == null) throw new IllegalArgumentException(\"Null not supported\");%n",
-                            varName);
+                    String nullCheck = String.format("if (%s == null) {\n%s = new java.util.ArrayList<>(); \n}%n",
+                            varName, varName);
                     setterBody = nullCheck + setterBody;
                 }
                 MethodDefinition setter = new MethodDefinition("void",
index 680fe50..3e0a741 100644 (file)
@@ -8,9 +8,7 @@
 package org.opendaylight.controller.config.yang.test.impl;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import static org.mockito.Mockito.doReturn;
 
 import com.google.common.collect.Lists;
@@ -112,15 +110,8 @@ public class NetconfTestImplModuleTest  extends AbstractConfigTest {
 
         ObjectName on = createInstance(transaction, instanceName, 4);
         NetconfTestImplModuleMXBean proxy = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class);
-        try{
-            proxy.setTestingDeps(null);
-            fail();
-        }catch(RuntimeException e) {
-            Throwable cause = e.getCause();
-            assertNotNull(cause);
-            assertTrue("Invalid type " + cause, cause instanceof IllegalArgumentException);
-            assertEquals("Null not supported", cause.getMessage());
-        }
+        proxy.setTestingDeps(null);
+        assertTrue(proxy.getTestingDeps().isEmpty());
         proxy.setTestingDeps(Collections.<ObjectName>emptyList());
     }