|
8 | 8 | import com.smartdevicelink.proxy.rpc.AddCommandResponse; |
9 | 9 | import com.smartdevicelink.proxy.rpc.DeleteCommand; |
10 | 10 | import com.smartdevicelink.proxy.rpc.DeleteCommandResponse; |
| 11 | +import com.smartdevicelink.proxy.rpc.ListFiles; |
11 | 12 | import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener; |
12 | 13 | import com.smartdevicelink.util.DebugTool; |
13 | 14 |
|
14 | 15 | import org.junit.Before; |
15 | 16 | import org.junit.Test; |
16 | 17 | import org.junit.runner.RunWith; |
| 18 | +import org.mockito.ArgumentMatchers; |
17 | 19 | import org.mockito.Mockito; |
18 | 20 | import org.mockito.invocation.InvocationOnMock; |
19 | 21 | import org.mockito.stubbing.Answer; |
@@ -74,6 +76,21 @@ public void onVoiceCommandSelected() { |
74 | 76 | List<VoiceCommand> deleteList = new ArrayList<>(); |
75 | 77 | List<VoiceCommand> addList = new ArrayList<>(); |
76 | 78 |
|
| 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 | + |
77 | 94 | @Before |
78 | 95 | public void setup() { |
79 | 96 | deleteList.clear(); |
@@ -316,7 +333,28 @@ public void testVoiceCommandsInListNotInSecondList() { |
316 | 333 |
|
317 | 334 | List<VoiceCommand> differencesList = voiceCommandUpdateOperation.voiceCommandsInListNotInSecondList(voiceCommandList, voiceCommandList2); |
318 | 335 | 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); |
319 | 344 |
|
| 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)); |
320 | 358 | } |
321 | 359 |
|
322 | 360 | } |
0 commit comments