[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r552 - in /projects/zb4osgi/trunk/zigbee.tester: ./ src/main/java/org/persona/zigbee/tester/gui/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/persona/ src/test/java/org/persona/zigbee/ src/test/java/org/persona/zigbee/tester/ src/test/java/org/persona/zigbee/tester/gui/

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Mon Oct 22 16:28:45 CEST 2012


Author: stefano.lenzi
Date: Mon Oct 22 16:28:45 2012
New Revision: 552

Log:
Fixing NPE when setting non-numeric parameter ( refs #134 )
Added Test Case for matching similar issue


Added:
    projects/zb4osgi/trunk/zigbee.tester/src/test/
    projects/zb4osgi/trunk/zigbee.tester/src/test/java/
    projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/
    projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/
    projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/
    projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/
    projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/
    projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/CommandTest.java
Modified:
    projects/zb4osgi/trunk/zigbee.tester/pom.xml
    projects/zb4osgi/trunk/zigbee.tester/src/main/java/org/persona/zigbee/tester/gui/Command.java

Modified: projects/zb4osgi/trunk/zigbee.tester/pom.xml
==============================================================================
--- projects/zb4osgi/trunk/zigbee.tester/pom.xml (original)
+++ projects/zb4osgi/trunk/zigbee.tester/pom.xml Mon Oct 22 16:28:45 2012
@@ -162,6 +162,26 @@
       <groupId>org.aaloa.zb4osgi</groupId>
       <artifactId>org.aaloa.zb4osgi.zigbee.basedriver.api</artifactId>
     </dependency>
+
+
+    <!-- 
+    	*NOTE*
+    	The following dependencies are used only for JUnit purpose, 
+    	but they will be resolved from OSGi enviroment at run-time 
+   	-->
+    <dependency>
+    	<groupId>org.slf4j</groupId>
+    	<artifactId>nlog4j</artifactId>
+    	<version>1.2.25</version>
+    </dependency>
+    <dependency>
+    	<groupId>org.aaloa.zb4osgi</groupId>
+    	<artifactId>org.aaloa.zb4osgi.zigbee.common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>    
   </dependencies>
 
   <properties>

Modified: projects/zb4osgi/trunk/zigbee.tester/src/main/java/org/persona/zigbee/tester/gui/Command.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.tester/src/main/java/org/persona/zigbee/tester/gui/Command.java (original)
+++ projects/zb4osgi/trunk/zigbee.tester/src/main/java/org/persona/zigbee/tester/gui/Command.java Mon Oct 22 16:28:45 2012
@@ -74,7 +74,6 @@
 		Class<?>[] params = method.getParameterTypes();
 		Object[] objs = new Object[params.length];
 		for (int i = 0; i < objs.length; i++) {
-			boolean assigned  = true;
 			try {
 				if ( params[i].isAssignableFrom( long.class ) ) objs[i] = Long.decode(values[i]).longValue();
 				else if ( params[i].isAssignableFrom( int.class ) )objs[i] = Integer.decode(values[i]).intValue();
@@ -83,10 +82,9 @@
 				else if ( params[i].isAssignableFrom( double.class ) ) objs[i] = Double.valueOf(values[i]).doubleValue();
 				else if ( params[i].isAssignableFrom( float.class ) ) objs[i] = Float.valueOf(values[i]).floatValue();
 			}catch (NumberFormatException ex){
-				assigned = false;
 				throw new CommandParsingException(values[i],i,"The parameter is a number and "+values[i]+" does not reppresent a number", ex);
-			}
-			if ( assigned ) continue;
+			}			
+			if ( objs[i] != null) continue; //Data already assigned 
 			
 			if ( params[i].isAssignableFrom( boolean.class ) ) objs[i] = Boolean.valueOf(values[i]).booleanValue() || "on".equalsIgnoreCase(values[i]) || "1".equals(values[i]);
 			else if ( params[i].isAssignableFrom( String.class ) ) objs[i] = values[i];

Added: projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/CommandTest.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/CommandTest.java (added)
+++ projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/CommandTest.java Mon Oct 22 16:28:45 2012
@@ -1,0 +1,61 @@
+/*
+
+   Copyright 2008-2010 CNR-ISTI, http://isti.cnr.it
+   Institute of Information Science and Technologies 
+   of the Italian National Research Council 
+
+
+   See the NOTICE file distributed with this work for additional 
+   information regarding copyright ownership
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+package org.persona.zigbee.tester.gui;
+
+import static org.junit.Assert.*;
+
+import java.lang.reflect.InvocationTargetException;
+
+import it.cnr.isti.zigbee.ha.cluster.impl.GroupsImpl;
+
+import org.junit.Test;
+
+/**
+ * 
+ * @author <a href="mailto:stefano.lenzi at isti.cnr.it">Stefano "Kismet" Lenzi</a>
+ * @version $LastChangedRevision$ ($LastChangedDate$)
+ * @since 0.4.0
+ */
+public class CommandTest {
+
+	@Test
+	public void testInvoke() {
+		Exception ex = null;
+		try {
+			//TODO We should use Mocking for better error handling rather then using the exception type
+			Command command = new Command(
+					new GroupsImpl(null), 
+					GroupsImpl.class.getMethod("addGroupIfIdentifying", int.class, String.class)
+			);
+			command.invoke(new String[]{"100","test"});
+		} catch (Exception e) {
+			e.printStackTrace();
+			assertTrue("Expected exception InvocationTargetException", e.getClass() == InvocationTargetException.class);
+			ex = (Exception) ((InvocationTargetException) e).getTargetException();
+		}
+		assertNotNull(ex);
+		assertTrue(ex.getClass() == NullPointerException.class);
+		assertNull("Expecting empty message for standard JRE NPE", ex.getMessage());
+	}
+
+}




More information about the Commit mailing list