diff options
author | Mikayla Ray <mikayla@livioconnect.com> | 2015-04-20 17:14:01 -0400 |
---|---|---|
committer | Mikayla Ray <mikayla@livioconnect.com> | 2015-04-20 17:14:01 -0400 |
commit | 62ea031af86aea13266639be846276fc464b4edb (patch) | |
tree | 49924f24e7f42fe99fd138e19e80cae42f90bf71 | |
parent | 816b235854e26905d9659f262e66c3cae45f1c7d (diff) | |
download | sdl_android-62ea031af86aea13266639be846276fc464b4edb.tar.gz |
Added unit tests for RPCStruct class
3 files changed, 56 insertions, 0 deletions
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/RPCStruct.java b/sdl_android_lib/src/com/smartdevicelink/proxy/RPCStruct.java index 1e633bf4a..477bbdde4 100644 --- a/sdl_android_lib/src/com/smartdevicelink/proxy/RPCStruct.java +++ b/sdl_android_lib/src/com/smartdevicelink/proxy/RPCStruct.java @@ -19,6 +19,10 @@ public class RPCStruct { return store.contains(key);
}
+ public Hashtable<String,Object> getStore () { // for unit testing
+ return store;
+ }
+
public RPCStruct() {
store = new Hashtable<String, Object>();
}
diff --git a/sdl_android_tests/src/com/smartdevicelink/test/proxy/RPCMessageTests.java b/sdl_android_tests/src/com/smartdevicelink/test/proxy/RPCMessageTests.java index 92b8ac744..a6e413384 100644 --- a/sdl_android_tests/src/com/smartdevicelink/test/proxy/RPCMessageTests.java +++ b/sdl_android_tests/src/com/smartdevicelink/test/proxy/RPCMessageTests.java @@ -44,6 +44,8 @@ public class RPCMessageTests extends TestCase { // so we cannot check against invalid data, including null values as it will // crash in it's attempt to assign a null key in the hashtable. // Function name and Message type should both have a check against null or invalid values. + // See Issue #165 + // Hashtable does not allow null keys or null values - consider changing to HashMap? // Test -- RPCMessage(Hashtable<String, Object> hash) Hashtable<String, Object> testHash = new Hashtable<String, Object>(); diff --git a/sdl_android_tests/src/com/smartdevicelink/test/proxy/RPCStructTests.java b/sdl_android_tests/src/com/smartdevicelink/test/proxy/RPCStructTests.java new file mode 100644 index 000000000..66e314c5b --- /dev/null +++ b/sdl_android_tests/src/com/smartdevicelink/test/proxy/RPCStructTests.java @@ -0,0 +1,50 @@ +package com.smartdevicelink.test.proxy; + +import java.util.Hashtable; + +import org.json.JSONException; + +import com.smartdevicelink.proxy.RPCStruct; + +import junit.framework.TestCase; + +public class RPCStructTests extends TestCase { + + private RPCStruct testRPCStruct = null; + + public void testStruct () { + assertNull("Expected null, but received object", testRPCStruct); + + // Test -- RPCStruct() + testRPCStruct = new RPCStruct(); + assertNotNull("RPCStruct should not be null, but was", testRPCStruct); + assertNotNull("RPCStruct hashtable 'store' should not be null, but was", testRPCStruct.getStore()); + + // Test -- RPCStruct(Hashtable<String, Object> hashtable) + Hashtable<String, Object> testHash = new Hashtable<String, Object>(); + testHash.put("test", new Object()); + testRPCStruct = new RPCStruct(testHash); + assertNotNull("RPCStruct should not be null, but was", testRPCStruct); + assertNotNull("RPCStruct hashtable 'store' should not be null, but was", testRPCStruct.getStore()); + assertTrue("Test value could not be retrieved from Hashtable", testRPCStruct.getStoreValue("test")); + assertNotNull("Test object was null", testRPCStruct.getStore().get("test")); + } + + public void testJSONStuff () { + try { + assertNotNull("Json object should not be null, but is", testRPCStruct.serializeJSON()); + } catch (JSONException e) { + fail("Json Exception was thrown"); + } + // TODO: test other json methods + } + + public void testBulkData () { + assertNull("Bulk data should be null, but wasn't", testRPCStruct.getBulkData()); + + byte[] testByteArray = {(byte) 0x00, (byte) 0x01}; + testRPCStruct.setBulkData(testByteArray); + assertNotNull("Bulk data should not be null, but is", testRPCStruct.getBulkData()); + } + +}
\ No newline at end of file |