Skip to content

Commit 74b62a9

Browse files
author
Julian Kast
committed
Fix errors found in unit test dealing with null check and fix unit test to test new logic correctly
1 parent a7c391d commit 74b62a9

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void testUpdatingCommands() {
182182

183183
// Fake onCommand - we want to make sure that we can pass back onCommand events to our VoiceCommand Objects
184184
OnCommand onCommand = new OnCommand();
185-
onCommand.setCmdID(command3.getCommandId());
185+
onCommand.setCmdID(voiceCommandManager.getVoiceCommands().get(voiceCommandManager.getVoiceCommands().indexOf(command3)).getCommandId());
186186
onCommand.setTriggerSource(TriggerSource.TS_VR); // these are voice commands
187187
commandListener.onNotified(onCommand); // send off the notification
188188

base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,28 @@ public void setVoiceCommands(List<VoiceCommand> voiceCommands) {
140140
// Clone voice commands
141141
this.voiceCommands = new ArrayList<>();
142142
for (VoiceCommand voiceCommand : voiceCommands) {
143+
if (voiceCommand == null) {
144+
continue;
145+
}
143146
this.voiceCommands.add(voiceCommand.clone());
144147
}
145148

146149
List<VoiceCommand> validatedVoiceCommands = removeEmptyVoiceCommands(this.voiceCommands);
147150

148151
if (validatedVoiceCommands.size() == 0 && voiceCommands.size() > 0) {
149152
DebugTool.logError(TAG, "New voice commands are invalid, skipping...");
153+
this.voiceCommands = null;
150154
return;
151155
}
152156

153157
if (!isVoiceCommandsUnique(validatedVoiceCommands)) {
154158
DebugTool.logError(TAG, "Not all voice command strings are unique across all voice commands. Voice commands will not be set.");
159+
this.voiceCommands = null;
155160
return;
156161
}
157162

163+
this.voiceCommands = validatedVoiceCommands;
164+
158165
updateIdsOnVoiceCommands(this.voiceCommands);
159166

160167
cleanTransactionQueue();

0 commit comments

Comments
 (0)