summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Kirk <askirk@umich.edu>2017-05-05 10:12:59 -0400
committerAustin Kirk <askirk@umich.edu>2017-05-05 10:12:59 -0400
commitba3118ad2e9460b07e9e5ecfec520bb648b281c6 (patch)
tree6cc67859fd13c5f30d35308fe2af93acac361b2f
parentd278cc0491b6f6761de166ca6bcb8fe3bb4e9d93 (diff)
downloadsdl_android-bugfix/utest_OnSdlChoiceChosen.tar.gz
Make SdlChoice class Json Serializablebugfix/utest_OnSdlChoiceChosen
-rw-r--r--sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSdlChoiceChosenTests.java32
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/OnSdlChoiceChosen.java154
2 files changed, 115 insertions, 71 deletions
diff --git a/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSdlChoiceChosenTests.java b/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSdlChoiceChosenTests.java
index 03ad7ed82..97efb7944 100644
--- a/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSdlChoiceChosenTests.java
+++ b/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSdlChoiceChosenTests.java
@@ -2,8 +2,8 @@ package com.smartdevicelink.test.rpc.notifications;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCMessage;
-import com.smartdevicelink.proxy.rpc.Choice;
import com.smartdevicelink.proxy.rpc.OnSdlChoiceChosen;
+import com.smartdevicelink.proxy.rpc.OnSdlChoiceChosen.SdlChoice;
import com.smartdevicelink.proxy.rpc.enums.TriggerSource;
import com.smartdevicelink.test.BaseRpcTests;
import com.smartdevicelink.test.Test;
@@ -13,18 +13,18 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
- * This is a unit test class for the SmartDeviceLink library project class :
+ * This is a unit test class for the SmartDeviceLink library project class :
* {@link com.smartdevicelink.proxy.rpc.OnSdlChoiceChosen}
*/
public class OnSdlChoiceChosenTests extends BaseRpcTests{
@Override
protected RPCMessage createMessage(){
- OnSdlChoiceChosen msg = new OnSdlChoiceChosen();
- Choice sdlChoice = Test.GENERAL_CHOICE;
-
+ OnSdlChoiceChosen msg = new OnSdlChoiceChosen();
+ SdlChoice sdlChoice = msg.new SdlChoice(Test.GENERAL_CHOICE);
+
msg.setTriggerSource(Test.GENERAL_TRIGGERSOURCE);
- msg.setSdlChoice(sdlChoice);
+ msg.setSdlChoice(sdlChoice);
return msg;
}
@@ -47,26 +47,26 @@ public class OnSdlChoiceChosenTests extends BaseRpcTests{
result.put(OnSdlChoiceChosen.KEY_TRIGGER_SOURCE, Test.GENERAL_TRIGGERSOURCE);
result.put(OnSdlChoiceChosen.KEY_SDL_CHOICE, Test.JSON_CHOICE);
}catch(JSONException e){
- fail(Test.JSON_FAIL);
+ fail(Test.JSON_FAIL);
}
return result;
}
/**
- * Tests the expected values of the RPC message.
- */
- public void testRpcValues () {
- // Test Values
- Choice data = ( (OnSdlChoiceChosen) msg ).getSdlChoice();
+ * Tests the expected values of the RPC message.
+ */
+ public void testRpcValues () {
+ // Test Values
+ SdlChoice data = ( (OnSdlChoiceChosen) msg ).getSdlChoice();
TriggerSource source = ( (OnSdlChoiceChosen) msg ).getTriggerSource();
-
+
// Valid Tests
- assertTrue(Test.MATCH, Validator.validateChoice(Test.GENERAL_CHOICE, data));
+ assertTrue(Test.MATCH, Validator.validateChoice(Test.GENERAL_CHOICE, data.getChoice()));
assertEquals(Test.MATCH, Test.GENERAL_TRIGGERSOURCE, source);
-
+
// Invalid/Null Tests
- OnSdlChoiceChosen msg = new OnSdlChoiceChosen();
+ OnSdlChoiceChosen msg = new OnSdlChoiceChosen();
assertNotNull(Test.NOT_NULL, msg);
testNullBase(msg);
diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/OnSdlChoiceChosen.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/OnSdlChoiceChosen.java
index 58285624f..5141ef0e8 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/OnSdlChoiceChosen.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/OnSdlChoiceChosen.java
@@ -2,54 +2,58 @@ package com.smartdevicelink.proxy.rpc;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCNotification;
+import com.smartdevicelink.proxy.RPCStruct;
import com.smartdevicelink.proxy.rpc.enums.TriggerSource;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import java.util.Hashtable;
import java.util.List;
public class OnSdlChoiceChosen extends RPCNotification {
public static final String KEY_SDL_CHOICE = "sdlChoice";
public static final String KEY_TRIGGER_SOURCE = "triggerSource";
-
+
public class SdlSubMenu {
private Integer _menuID = null;
@SuppressWarnings("unused")
- private Integer _position = null;
+ private Integer _position = null;
private String _menuName = null;
-
+
// Constructor
SdlSubMenu(Integer menuID, Integer position, String menuName) {
_menuID = menuID;
_position = position;
_menuName = menuName;
}
-
+
// Restrict no-arg constructor
@SuppressWarnings("unused")
- private SdlSubMenu() {}
-
+ private SdlSubMenu() {}
+
// Public Getters
public Integer getMenuID() {
return _menuID;
}
-
+
public String getMenuName() {
return _menuName;
}
-
+
public String toString() {
return _menuName;
}
}
-
+
public class SdlCommand {
private Integer _commandID = null;
private SdlSubMenu _parentSubMenu = null;
@SuppressWarnings("unused")
- private Integer _position = null;
+ private Integer _position = null;
private String _menuName = null;
private List<String> _vrCommands = null;
-
+
// Constructor
SdlCommand(Integer commandID, SdlSubMenu parentSubMenu, Integer position, String menuName, List<String> vrCommands) {
_commandID = commandID;
@@ -58,54 +62,94 @@ public class OnSdlChoiceChosen extends RPCNotification {
_menuName = menuName;
_vrCommands = vrCommands;
}
-
+
// Restrict no-arg constructor
@SuppressWarnings("unused")
- private SdlCommand() {}
-
+ private SdlCommand() {}
+
// Public Getters
public Integer getCommandID() {
return _commandID;
}
-
+
public SdlSubMenu getParentSubMenu() {
return _parentSubMenu;
}
-
+
public String getMenuName() {
return _menuName;
}
-
+
public List<String> getVrCommands() {
return _vrCommands;
}
-
+
public String toString() {
return _menuName;
}
}
-
+
+ public class SdlChoice extends RPCStruct {
+
+ private Choice _choice = null;
+
+ @Override
+ public JSONObject serializeJSON() throws JSONException {
+ return _choice.serializeJSON();
+ }
+
+ @Override
+ public JSONObject serializeJSON(byte version) throws JSONException {
+ return _choice.serializeJSON(version);
+ }
+
+ // Constructor
+ public SdlChoice(Choice choice) {
+ _choice = choice;
+ }
+
+ public Choice getChoice() {
+ return _choice;
+ }
+
+ public Integer getChoiceID() {
+ return _choice.getChoiceID();
+ }
+
+ public String getMenuName() {
+ return _choice.getMenuName();
+ }
+
+ public List<String> getVrCommands() {
+ return _choice.getVrCommands();
+ }
+
+ public String toString() {
+ return _choice.getMenuName();
+ }
+ }
+
public class SdlChoiceSet {
private Integer _choiceSetID = null;
- private List<Choice> _choiceSet = null;
-
+ private List<SdlChoice> _choiceSet = null;
+
// Constructor
- SdlChoiceSet(Integer choiceSetID, List<Choice> choiceSet) {
+ SdlChoiceSet(Integer choiceSetID, List<SdlChoice> choiceSet) {
_choiceSetID = choiceSetID;
_choiceSet = choiceSet;
}
-
+
public Integer getChoiceSetID() {
return _choiceSetID;
}
-
- public List<Choice> getChoiceSet() {
+
+ public List<SdlChoice> getChoiceSet() {
return _choiceSet;
}
}
-
-
-
+
+
+
public OnSdlChoiceChosen() {
super(FunctionID.ON_SDL_CHOICE_CHOSEN.toString());
@@ -113,30 +157,30 @@ public class OnSdlChoiceChosen extends RPCNotification {
public OnSdlChoiceChosen(Hashtable<String, Object> hash){
super(hash);
}
- public Choice getSdlChoice() {
- return (Choice) parameters.get(KEY_SDL_CHOICE);
- }
- public void setSdlChoice(Choice sdlChoice) {
- if (sdlChoice != null) {
- parameters.put(KEY_SDL_CHOICE, sdlChoice);
- } else {
- parameters.remove(KEY_SDL_CHOICE);
- }
- }
- public TriggerSource getTriggerSource() {
- Object obj = parameters.get(KEY_TRIGGER_SOURCE);
- if (obj instanceof TriggerSource) {
- return (TriggerSource) obj;
- } else if (obj instanceof String) {
- return TriggerSource.valueForString((String) obj);
- }
- return null;
- }
- public void setTriggerSource( TriggerSource triggerSource ) {
- if (triggerSource != null) {
- parameters.put(KEY_TRIGGER_SOURCE, triggerSource );
- } else {
- parameters.remove(KEY_TRIGGER_SOURCE);
- }
- }
-}
+ public SdlChoice getSdlChoice() {
+ return (SdlChoice) parameters.get(KEY_SDL_CHOICE);
+ }
+ public void setSdlChoice(SdlChoice sdlChoice) {
+ if (sdlChoice != null) {
+ parameters.put(KEY_SDL_CHOICE, sdlChoice);
+ } else {
+ parameters.remove(KEY_SDL_CHOICE);
+ }
+ }
+ public TriggerSource getTriggerSource() {
+ Object obj = parameters.get(KEY_TRIGGER_SOURCE);
+ if (obj instanceof TriggerSource) {
+ return (TriggerSource) obj;
+ } else if (obj instanceof String) {
+ return TriggerSource.valueForString((String) obj);
+ }
+ return null;
+ }
+ public void setTriggerSource( TriggerSource triggerSource ) {
+ if (triggerSource != null) {
+ parameters.put(KEY_TRIGGER_SOURCE, triggerSource );
+ } else {
+ parameters.remove(KEY_TRIGGER_SOURCE);
+ }
+ }
+} \ No newline at end of file