summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2019-09-05 13:31:55 -0400
committerNicoleYarroch <nicole@livio.io>2019-09-05 13:31:55 -0400
commitf6c277940915d527de16ae012fbb4ab72c230439 (patch)
treee11ea42351e6e91cdd1e843b30661927c182ebfc
parent0e7be341c128bd913602d76e6cc2781886e80466 (diff)
downloadsdl_android-f6c277940915d527de16ae012fbb4ab72c230439.tar.gz
Fixed cancel keyboard operation tests
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java309
1 files changed, 191 insertions, 118 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java
index ce3e785f3..def421a6b 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java
@@ -53,25 +53,32 @@ import com.smartdevicelink.test.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class PresentKeyboardOperationTests extends AndroidTestCase2 {
private PresentKeyboardOperation presentKeyboardOperation;
+ private KeyboardListener keyboardListener;
private ISdl internalInterface;
+ private ExecutorService executor;
+
@Override
public void setUp() throws Exception{
super.setUp();
internalInterface = mock(ISdl.class);
- KeyboardListener keyboardListener = mock(KeyboardListener.class);
-
- presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, getKeyBoardProperties(), "Test", null, keyboardListener, Test.GENERAL_INTEGER);
+ keyboardListener = mock(KeyboardListener.class);
Answer<Void> setGlobalPropertiesAnswer = new Answer<Void>() {
@Override
@@ -88,7 +95,7 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 {
};
doAnswer(setGlobalPropertiesAnswer).when(internalInterface).sendRPC(any(SetGlobalProperties.class));
- presentKeyboardOperation.sdlMsgVersion = new SdlMsgVersion(6,0);
+ executor = Executors.newCachedThreadPool();
}
@Override
@@ -96,7 +103,17 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 {
super.tearDown();
}
+ private KeyboardProperties getKeyBoardProperties(){
+ KeyboardProperties properties = new KeyboardProperties();
+ properties.setLanguage(Language.EN_US);
+ properties.setKeyboardLayout(KeyboardLayout.QWERTZ);
+ properties.setKeypressMode(KeypressMode.RESEND_CURRENT_ENTRY);
+ return properties;
+ }
+
public void testGetPerformInteraction(){
+ presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, getKeyBoardProperties(), "Test", null, keyboardListener, Test.GENERAL_INTEGER);
+
PerformInteraction pi = presentKeyboardOperation.getPerformInteraction();
assertEquals(pi.getInitialText(), "Test");
assertNull(pi.getHelpPrompt());
@@ -106,120 +123,176 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 {
assertEquals(pi.getCancelID(), Test.GENERAL_INTEGER);
}
- private KeyboardProperties getKeyBoardProperties(){
- KeyboardProperties properties = new KeyboardProperties();
- properties.setLanguage(Language.EN_US);
- properties.setKeyboardLayout(KeyboardLayout.QWERTZ);
- properties.setKeypressMode(KeypressMode.RESEND_CURRENT_ENTRY);
- return properties;
+ public void testCancelingKeyboardSuccessfullyIfThreadIsRunning(){
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
+ presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, null, "Test", null, null, Test.GENERAL_INTEGER);
+ executor.execute(presentKeyboardOperation);
+ try {
+ executor.awaitTermination(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ assertTrue(false);
+ }
+
+ assertTrue(presentKeyboardOperation.isExecuting());
+ assertFalse(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+
+ presentKeyboardOperation.dismissKeyboard();
+ Answer<Void> cancelInteractionAnswer = new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ CancelInteraction cancelInteraction = (CancelInteraction) args[0];
+
+ assertEquals(cancelInteraction.getCancelID(), Test.GENERAL_INTEGER);
+ assertEquals(cancelInteraction.getInteractionFunctionID().intValue(), FunctionID.PERFORM_INTERACTION.getId());
+
+ RPCResponse response = new RPCResponse(FunctionID.CANCEL_INTERACTION.toString());
+ response.setSuccess(true);
+ cancelInteraction.getOnRPCResponseListener().onResponse(0, response);
+
+ return null;
+ }
+ };
+ doAnswer(cancelInteractionAnswer).when(internalInterface).sendRPC(any(CancelInteraction.class));
+
+ verify(internalInterface, times(1)).sendRPC(any(CancelInteraction.class));
+ verify(internalInterface, times(1)).sendRPC(any(PerformInteraction.class));
+
+ assertTrue(presentKeyboardOperation.isExecuting());
+ assertFalse(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+ }
+
+ public void testCancelingKeyboardUnsuccessfullyIfThreadIsRunning(){
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
+ presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, null, "Test", null, null, Test.GENERAL_INTEGER);
+ executor.execute(presentKeyboardOperation);
+ try {
+ executor.awaitTermination(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ assertTrue(false);
+ }
+
+ presentKeyboardOperation.dismissKeyboard();
+ Answer<Void> cancelInteractionAnswer = new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ CancelInteraction cancelInteraction = (CancelInteraction) args[0];
+
+ assertEquals(cancelInteraction.getCancelID(), Test.GENERAL_INTEGER);
+ assertEquals(cancelInteraction.getInteractionFunctionID().intValue(), FunctionID.PERFORM_INTERACTION.getId());
+
+ RPCResponse response = new RPCResponse(FunctionID.CANCEL_INTERACTION.toString());
+ response.setSuccess(false);
+ cancelInteraction.getOnRPCResponseListener().onResponse(0, response);
+
+ return null;
+ }
+ };
+ doAnswer(cancelInteractionAnswer).when(internalInterface).sendRPC(any(CancelInteraction.class));
+
+ verify(internalInterface, times(1)).sendRPC(any(CancelInteraction.class));
+ verify(internalInterface, times(1)).sendRPC(any(PerformInteraction.class));
+
+ assertTrue(presentKeyboardOperation.isExecuting());
+ assertFalse(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+ }
+
+ public void testCancelingKeyboardIfThreadHasFinished(){
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
+ presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, null, "Test", null, null, Test.GENERAL_INTEGER);
+ presentKeyboardOperation.finishOperation();
+
+ assertFalse(presentKeyboardOperation.isExecuting());
+ assertTrue(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+
+ presentKeyboardOperation.dismissKeyboard();
+ verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
+
+ assertFalse(presentKeyboardOperation.isExecuting());
+ assertTrue(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+ }
+
+ public void testCancelingKeyboardIfThreadHasNotYetRun(){
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
+ presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, null, "Test", null, null, Test.GENERAL_INTEGER);
+
+ assertFalse(presentKeyboardOperation.isExecuting());
+ assertFalse(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+
+ presentKeyboardOperation.dismissKeyboard();
+
+ // Once the operation has started
+ executor.execute(presentKeyboardOperation);
+ try {
+ executor.awaitTermination(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ assertTrue(false);
+ }
+
+ assertFalse(presentKeyboardOperation.isExecuting());
+ assertTrue(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+
+ // Make sure neither a `CancelInteraction` or `PerformInteraction` RPC is ever sent
+ verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
+ verify(internalInterface, never()).sendRPC(any(PerformInteraction.class));
+ }
+
+ public void testCancelingChoiceSetIfHeadUnitDoesNotSupportFeature(){
+ // Cancel Interaction is only supported on RPC specs v.6.0.0+
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(5, 3));
+ presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, null, "Test", null, null, Test.GENERAL_INTEGER);
+ executor.execute(presentKeyboardOperation);
+ try {
+ executor.awaitTermination(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ assertTrue(false);
+ }
+
+ assertTrue(presentKeyboardOperation.isExecuting());
+ assertFalse(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+
+ presentKeyboardOperation.dismissKeyboard();
+
+ verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
+ verify(internalInterface, times(1)).sendRPC(any(PerformInteraction.class));
}
-// public void testCancelingKeyboardSuccessfullyIfThreadIsRunning(){
-// presentKeyboardOperation.run();
-//
-// Answer<Void> cancelInteractionAnswer = new Answer<Void>() {
-// @Override
-// public Void answer(InvocationOnMock invocation) {
-// Object[] args = invocation.getArguments();
-// CancelInteraction cancelInteraction = (CancelInteraction) args[0];
-//
-// assertEquals(cancelInteraction.getCancelID(), Test.GENERAL_INTEGER);
-// assertEquals(cancelInteraction.getInteractionFunctionID().intValue(), FunctionID.PERFORM_INTERACTION.getId());
-//
-// RPCResponse response = new RPCResponse(FunctionID.CANCEL_INTERACTION.toString());
-// response.setSuccess(true);
-// cancelInteraction.getOnRPCResponseListener().onResponse(0, response);
-//
-// return null;
-// }
-// };
-// doAnswer(cancelInteractionAnswer).when(internalInterface).sendRPC(any(CancelInteraction.class));
-//
-// presentKeyboardOperation.dismissKeyboard();
-//
-// assertTrue(presentKeyboardOperation.isExecuting());
-// assertFalse(presentKeyboardOperation.isFinished());
-// }
-//
-// public void testCancelingKeyboardUnsuccessfullyIfThreadIsRunning(){
-// presentKeyboardOperation.run();
-//
-// Answer<Void> cancelInteractionAnswer = new Answer<Void>() {
-// @Override
-// public Void answer(InvocationOnMock invocation) {
-// Object[] args = invocation.getArguments();
-// CancelInteraction cancelInteraction = (CancelInteraction) args[0];
-//
-// assertEquals(cancelInteraction.getCancelID(), Test.GENERAL_INTEGER);
-// assertEquals(cancelInteraction.getInteractionFunctionID().intValue(), FunctionID.PERFORM_INTERACTION.getId());
-//
-// RPCResponse response = new RPCResponse(FunctionID.CANCEL_INTERACTION.toString());
-// response.setSuccess(false);
-// cancelInteraction.getOnRPCResponseListener().onResponse(0, response);
-//
-// return null;
-// }
-// };
-// doAnswer(cancelInteractionAnswer).when(internalInterface).sendRPC(any(CancelInteraction.class));
-//
-// presentKeyboardOperation.dismissKeyboard();
-//
-// assertTrue(presentKeyboardOperation.isExecuting());
-// assertFalse(presentKeyboardOperation.isFinished());
-// }
-//
-// public void testCancelingKeyboardIfThreadHasFinished(){
-// presentKeyboardOperation.run();
-// presentKeyboardOperation.finishOperation();
-//
-// presentKeyboardOperation.dismissKeyboard();
-//
-// verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
-//
-// assertFalse(presentKeyboardOperation.isExecuting());
-// assertTrue(presentKeyboardOperation.isFinished());
-// }
-//
-// public void testCancelingKeyboardIfThreadHasNotYetRun(){
-// presentKeyboardOperation.dismissKeyboard();
-//
-// // Make sure neither a `CancelInteraction` or `PerformInteraction` RPC is sent
-// verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
-// verify(internalInterface, never()).sendRPC(any(PerformInteraction.class));
-//
-// assertFalse(presentKeyboardOperation.isExecuting());
-// assertFalse(presentKeyboardOperation.isFinished());
-// }
-//
-// public void testCancelingChoiceSetIfHeadUnitDoesNotSupportFeature(){
-// // Only supported with RPC spec versions 6.0.0+
-// presentKeyboardOperation.sdlMsgVersion = new SdlMsgVersion(5, 3);
-// presentKeyboardOperation.run();
-//
-// assertTrue(presentKeyboardOperation.isExecuting());
-// assertFalse(presentKeyboardOperation.isFinished());
-//
-// presentKeyboardOperation.dismissKeyboard();
-//
-// verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
-// }
-//
-// public void testCancelingChoiceSetIfHeadUnitDoesNotSupportFeatureButThreadIsNotRunning(){
-// // Only supported with RPC spec versions 6.0.0+
-// presentKeyboardOperation.sdlMsgVersion = new SdlMsgVersion(5, 3);
-//
-// presentKeyboardOperation.dismissKeyboard();
-//
-// verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
-//
-// // Once the thread has started
-// presentKeyboardOperation.run();
-//
-// // Make sure neither a `CancelInteraction` or `PerformInteraction` RPC is sent
-// verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
-// verify(internalInterface, never()).sendRPC(any(PerformInteraction.class));
-//
-// assertFalse(presentKeyboardOperation.isExecuting());
-// assertTrue(presentKeyboardOperation.isFinished());
-// }
+ public void testCancelingChoiceSetIfHeadUnitDoesNotSupportFeatureButThreadIsNotRunning(){
+ // Cancel Interaction is only supported on RPC specs v.6.0.0+
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(5, 3));
+ presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, null, "Test", null, null, Test.GENERAL_INTEGER);
+
+ assertFalse(presentKeyboardOperation.isExecuting());
+ assertFalse(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+
+ presentKeyboardOperation.dismissKeyboard();
+
+ verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
+
+ // Once the operation has started
+ executor.execute(presentKeyboardOperation);
+ try {
+ executor.awaitTermination(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ assertTrue(false);
+ }
+
+ assertFalse(presentKeyboardOperation.isExecuting());
+ assertTrue(presentKeyboardOperation.isFinished());
+ assertFalse(presentKeyboardOperation.isCancelled());
+
+ // Make sure neither a `CancelInteraction` or `PerformInteraction` RPC is ever sent
+ verify(internalInterface, never()).sendRPC(any(CancelInteraction.class));
+ verify(internalInterface, never()).sendRPC(any(PerformInteraction.class));
+ }
}