diff options
author | BrettyWhite <geekman3454@protonmail.com> | 2019-06-11 11:41:11 -0400 |
---|---|---|
committer | BrettyWhite <geekman3454@protonmail.com> | 2019-06-11 11:41:11 -0400 |
commit | 56432e1988e180e1232830cd9c61fbba6a2c0c72 (patch) | |
tree | 64d4290aa5ff11c360aa9f91574355691e2b7d4d | |
parent | 1a00ad8fe6c42ce14b574add119991fc95310203 (diff) | |
download | sdl_android-56432e1988e180e1232830cd9c61fbba6a2c0c72.tar.gz |
delete choices operation tests
2 files changed, 65 insertions, 23 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperationTests.java index 6745fbd17..5422323cf 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperationTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperationTests.java @@ -35,12 +35,31 @@ package com.smartdevicelink.managers.screen.choiceset.operations; import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.screen.choiceset.ChoiceCell; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSet; + +import java.util.HashSet; +import java.util.List; + +import static org.mockito.Mockito.mock; public class DeleteChoicesOperationTests extends AndroidTestCase2 { + private DeleteChoicesOperation deleteChoicesOperation; + @Override public void setUp() throws Exception{ super.setUp(); + + ChoiceCell cell1 = new ChoiceCell("cell 1"); + ChoiceCell cell2 = new ChoiceCell("cell 2"); + HashSet<ChoiceCell> cellsToDelete = new HashSet<>(); + cellsToDelete.add(cell1); + cellsToDelete.add(cell2); + + ISdl internalInterface = mock(ISdl.class); + deleteChoicesOperation = new DeleteChoicesOperation(internalInterface, cellsToDelete, null); } @Override @@ -48,4 +67,13 @@ public class DeleteChoicesOperationTests extends AndroidTestCase2 { super.tearDown(); } + public void testCreateListDeleteInteractionSets(){ + List<DeleteInteractionChoiceSet> deletes = deleteChoicesOperation.createDeleteSets(); + assertNotNull(deletes); + assertEquals(deletes.size(), 2); + for (DeleteInteractionChoiceSet delete : deletes) { + assertNotNull(delete); + } + } + } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperation.java index 08b127120..c53b03d0c 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperation.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperation.java @@ -68,36 +68,50 @@ public class DeleteChoicesOperation implements Runnable { private void sendDeletions(){ - List<DeleteInteractionChoiceSet> deleteChoices = new ArrayList<>(cellsToDelete.size()); - for (ChoiceCell cell : cellsToDelete){ - deleteChoices.add(new DeleteInteractionChoiceSet(cell.getChoiceId())); - } + List<DeleteInteractionChoiceSet> deleteChoices = createDeleteSets(); + + if (deleteChoices.size() > 0) { - if (internalInterface.get() != null){ - internalInterface.get().sendRequests(deleteChoices, new OnMultipleRequestListener() { - @Override - public void onUpdate(int remainingRequests) {} + if (internalInterface.get() != null) { + internalInterface.get().sendRequests(deleteChoices, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + } - @Override - public void onFinished() { - if (completionListener != null){ - completionListener.onComplete(true); + @Override + public void onFinished() { + if (completionListener != null) { + completionListener.onComplete(true); + } + DebugTool.logInfo("Successfully deleted choices"); } - DebugTool.logInfo("Successfully deleted choices"); - } - @Override - public void onError(int correlationId, Result resultCode, String info) { - if (completionListener != null){ - completionListener.onComplete(false); + @Override + public void onError(int correlationId, Result resultCode, String info) { + if (completionListener != null) { + completionListener.onComplete(false); + } + DebugTool.logError("Failed to delete choice: " + info + " | Corr ID: " + correlationId); } - DebugTool.logError("Failed to delete choice: "+ info+ " | Corr ID: "+ correlationId); - } - @Override - public void onResponse(int correlationId, RPCResponse response) {} - }); + @Override + public void onResponse(int correlationId, RPCResponse response) { + } + }); + } + } else{ + if (completionListener != null) { + completionListener.onComplete(true); + } + DebugTool.logInfo("No Choices to delete, continue"); } + } + List<DeleteInteractionChoiceSet> createDeleteSets(){ + List<DeleteInteractionChoiceSet> deleteChoices = new ArrayList<>(cellsToDelete.size()); + for (ChoiceCell cell : cellsToDelete){ + deleteChoices.add(new DeleteInteractionChoiceSet(cell.getChoiceId())); + } + return deleteChoices; } } |