From 956c4b08a3acd9259fdfb33c7f0c11f70c221984 Mon Sep 17 00:00:00 2001 From: Bilal Alsharifi Date: Fri, 31 Jul 2020 10:50:51 -0400 Subject: Add RPCStruct ClassCastException unit tests --- .../smartdevicelink/test/proxy/RPCStructTests.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'android') diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/RPCStructTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/RPCStructTests.java index a61c9558e..5542719ba 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/RPCStructTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/RPCStructTests.java @@ -155,4 +155,32 @@ public class RPCStructTests extends TestCase { testStruct.setValue(invalidKey, TestValues.GENERAL_STRING); assertNull(testStruct.getObject(Integer.class, invalidKey)); } + + public void testGetFloat() { + Hashtable map = new Hashtable<>(); + String key = "test"; + Double value = 42.00; + map.put(key, value); + RPCStruct rpcStruct = new RPCStruct(map); + try { + Float value2 = rpcStruct.getFloat(key); + assertTrue(value2 - value < 0.1); + } catch (ClassCastException e) { + fail(e.getMessage()); + } + } + + public void testGetDouble() { + Hashtable map = new Hashtable<>(); + String key = "test"; + Integer value = 42; + map.put(key, value); + RPCStruct rpcStruct = new RPCStruct(map); + try { + Double value2 = rpcStruct.getDouble(key); + assertTrue(value2 - value < 0.1); + } catch (ClassCastException e) { + fail(e.getMessage()); + } + } } -- cgit v1.2.1