Skip to content

Commit 7882136

Browse files
author
Julian Kast
committed
Add unit test for deleting voiceCommands
1 parent f2b533b commit 7882136

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import com.smartdevicelink.proxy.rpc.AddCommandResponse;
99
import com.smartdevicelink.proxy.rpc.DeleteCommand;
1010
import com.smartdevicelink.proxy.rpc.DeleteCommandResponse;
11+
import com.smartdevicelink.proxy.rpc.ListFiles;
1112
import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener;
1213
import com.smartdevicelink.util.DebugTool;
1314

1415
import org.junit.Before;
1516
import org.junit.Test;
1617
import org.junit.runner.RunWith;
18+
import org.mockito.ArgumentMatchers;
1719
import org.mockito.Mockito;
1820
import org.mockito.invocation.InvocationOnMock;
1921
import org.mockito.stubbing.Answer;
@@ -74,6 +76,21 @@ public void onVoiceCommandSelected() {
7476
List<VoiceCommand> deleteList = new ArrayList<>();
7577
List<VoiceCommand> addList = new ArrayList<>();
7678

79+
private Answer<Void> onListFilesSuccess = new Answer<Void>() {
80+
@Override
81+
public Void answer(InvocationOnMock invocation) {
82+
Object[] args = invocation.getArguments();
83+
RPCRequest message = (RPCRequest) args[0];
84+
if (message instanceof ListFiles) {
85+
int correlationId = message.getCorrelationID();
86+
DeleteCommandResponse deleteCommandResponse = new DeleteCommandResponse();
87+
deleteCommandResponse.setSuccess(true);
88+
message.getOnRPCResponseListener().onResponse(correlationId, deleteCommandResponse);
89+
}
90+
return null;
91+
}
92+
};
93+
7794
@Before
7895
public void setup() {
7996
deleteList.clear();
@@ -316,7 +333,28 @@ public void testVoiceCommandsInListNotInSecondList() {
316333

317334
List<VoiceCommand> differencesList = voiceCommandUpdateOperation.voiceCommandsInListNotInSecondList(voiceCommandList, voiceCommandList2);
318335
assertEquals(differencesList.size(), 1);
336+
}
337+
338+
@Test
339+
public void testDelete() {
340+
internalInterface = mock(ISdl.class);
341+
342+
VoiceCommand command1 = new VoiceCommand(Collections.singletonList("Command 1"), null);
343+
VoiceCommand command2 = new VoiceCommand(Collections.singletonList("Command 2"), null);
319344

345+
VoiceCommand command1Clone = new VoiceCommand(Collections.singletonList("Command 1"), null);
346+
VoiceCommand command3 = new VoiceCommand(Collections.singletonList("Command 3"), null);
347+
348+
List<VoiceCommand> voiceCommandList = new ArrayList<>();
349+
voiceCommandList.add(command1);
350+
voiceCommandList.add(command2);
351+
352+
List<VoiceCommand> voiceCommandList2 = new ArrayList<>();
353+
voiceCommandList2.add(command1Clone);
354+
voiceCommandList2.add(command3);
355+
VoiceCommandUpdateOperation voiceCommandUpdateOperation = new VoiceCommandUpdateOperation(internalInterface, voiceCommandList, voiceCommandList2, null);
356+
voiceCommandUpdateOperation.onExecute();
357+
verify(internalInterface, times(1)).sendRPCs(ArgumentMatchers.<DeleteCommand>anyList(), any(OnMultipleRequestListener.class));
320358
}
321359

322360
}

0 commit comments

Comments
 (0)