diff options
author | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2020-06-12 13:46:19 -0400 |
---|---|---|
committer | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2020-06-12 13:46:19 -0400 |
commit | fe0b4dd829c6f2c1598102638f877b1da8595276 (patch) | |
tree | e558eddb1d78aecfc847927ad2ae586c19c077c3 | |
parent | 1b15fb34eceec0b7715477c23f9073824638719c (diff) | |
download | sdl_android-fe0b4dd829c6f2c1598102638f877b1da8595276.tar.gz |
Fix unit tests
6 files changed, 94 insertions, 123 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java index 84865f21e..bf0dc3a99 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java @@ -2,6 +2,7 @@ package com.smartdevicelink.managers; import android.content.Context; +import com.livio.taskmaster.Taskmaster; import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.managers.lifecycle.LifecycleConfigurationUpdate; import com.smartdevicelink.managers.lockscreen.LockScreenConfig; @@ -35,6 +36,7 @@ import java.util.Vector; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * This is a unit test class for the SmartDeviceLink library manager class : @@ -137,6 +139,7 @@ public class SdlManagerTests extends AndroidTestCase2 { // mock internalInterface and set it manually internalInterface = mock(ISdl.class); + when(internalInterface.getTaskmaster()).thenReturn(new Taskmaster.Builder().build()); manager._internalInterface = internalInterface; return manager; diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java index 34cebfc08..0e22b3b68 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java @@ -1,5 +1,6 @@ package com.smartdevicelink.managers.screen; +import com.livio.taskmaster.Taskmaster; import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.file.FileManager; @@ -15,6 +16,7 @@ import java.util.Arrays; import java.util.List; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * This is a unit test class for the SmartDeviceLink library manager class : @@ -28,7 +30,9 @@ public class ScreenManagerTests extends AndroidTestCase2 { public void setUp() throws Exception { super.setUp(); + ISdl internalInterface = mock(ISdl.class); + when(internalInterface.getTaskmaster()).thenReturn(new Taskmaster.Builder().build()); FileManager fileManager = mock(FileManager.class); screenManager = new ScreenManager(internalInterface, fileManager); screenManager.start(null); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManagerTests.java index 1a9efffbe..31f16b315 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManagerTests.java @@ -35,6 +35,7 @@ package com.smartdevicelink.managers.screen.choiceset; +import com.livio.taskmaster.Taskmaster; import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.file.FileManager; @@ -52,7 +53,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.concurrent.LinkedBlockingQueue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -64,6 +64,7 @@ import static org.mockito.Mockito.when; public class ChoiceSetManagerTests extends AndroidTestCase2 { private ChoiceSetManager csm; + Taskmaster taskmaster; @Override public void setUp() throws Exception{ @@ -71,6 +72,8 @@ public class ChoiceSetManagerTests extends AndroidTestCase2 { ISdl internalInterface = mock(ISdl.class); FileManager fileManager = mock(FileManager.class); + taskmaster = new Taskmaster.Builder().build(); + when(internalInterface.getTaskmaster()).thenReturn(taskmaster); csm = new ChoiceSetManager(internalInterface, fileManager); assertEquals(csm.getState(), BaseSubManager.SETTING_UP); @@ -83,7 +86,6 @@ public class ChoiceSetManagerTests extends AndroidTestCase2 { assertNotNull(csm.preloadedChoices); assertNotNull(csm.pendingPreloadChoices); assertNotNull(csm.operationQueue); - assertNotNull(csm.executor); assertNotNull(csm.hmiListener); assertNotNull(csm.onDisplayCapabilityListener); assertNull(csm.pendingPresentOperation); @@ -100,10 +102,9 @@ public class ChoiceSetManagerTests extends AndroidTestCase2 { assertNull(csm.pendingPresentationSet); assertNull(csm.pendingPresentOperation); - assertEquals(csm.operationQueue.size(), 0); + assertEquals(csm.operationQueue.getTasksAsList().size(), 0); assertEquals(csm.nextChoiceId, 1); - assertTrue(csm.executor.isShutdown()); assertFalse(csm.isVROptional); assertEquals(csm.getState(), BaseSubManager.SHUTDOWN); @@ -242,6 +243,7 @@ public class ChoiceSetManagerTests extends AndroidTestCase2 { public void testPresentingKeyboardShouldReturnCancelIDIfKeyboardCanBeSent() { ISdl internalInterface = mock(ISdl.class); + when(internalInterface.getTaskmaster()).thenReturn(taskmaster); FileManager fileManager = mock(FileManager.class); ChoiceSetManager newCSM = new ChoiceSetManager(internalInterface, fileManager); @@ -254,6 +256,7 @@ public class ChoiceSetManagerTests extends AndroidTestCase2 { public void testPresentingKeyboardShouldNotReturnCancelIDIfKeyboardCannotBeSent() { ISdl internalInterface = mock(ISdl.class); + when(internalInterface.getTaskmaster()).thenReturn(taskmaster); FileManager fileManager = mock(FileManager.class); ChoiceSetManager newCSM = new ChoiceSetManager(internalInterface, fileManager); @@ -278,17 +281,13 @@ public class ChoiceSetManagerTests extends AndroidTestCase2 { // Currently executing operation PresentKeyboardOperation testKeyboardOp = mock(PresentKeyboardOperation.class); - doReturn(true).when(testKeyboardOp).isExecuting(); doReturn(96).when(testKeyboardOp).getCancelID(); csm.currentlyPresentedKeyboardOperation = testKeyboardOp; // Queued operations PresentKeyboardOperation testKeyboardOp2 = mock(PresentKeyboardOperation.class); - doReturn(true).when(testKeyboardOp2).isExecuting(); doReturn(testCancelID).when(testKeyboardOp2).getCancelID(); - LinkedBlockingQueue<Runnable> testOperationQueue = new LinkedBlockingQueue<>(); - testOperationQueue.add(testKeyboardOp2); - csm.operationQueue = testOperationQueue; + csm.currentlyPresentedKeyboardOperation = testKeyboardOp2; // Queued operation should be canceled csm.dismissKeyboard(testCancelID); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java index d8cf5be9d..e3031376f 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java @@ -35,6 +35,9 @@ package com.smartdevicelink.managers.screen.choiceset; +import com.livio.taskmaster.Queue; +import com.livio.taskmaster.Task; +import com.livio.taskmaster.Taskmaster; import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCResponse; @@ -54,9 +57,6 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.Collections; -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; @@ -74,7 +74,8 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { private KeyboardListener keyboardListener; private ChoiceSetSelectionListener choiceSetSelectionListener; - private ExecutorService executor; + private Taskmaster taskmaster; + private Queue queue; @Override public void setUp() throws Exception{ @@ -89,7 +90,9 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { cell1.setChoiceId(0); choiceSet = new ChoiceSet("Test", Collections.singletonList(cell1), choiceSetSelectionListener); - executor = Executors.newCachedThreadPool(); + taskmaster = new Taskmaster.Builder().build(); + queue = taskmaster.createQueue("test", 100, false); + taskmaster.start(); } @Override @@ -135,18 +138,22 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { assertEquals(presentChoiceSetOperation.selectedCellRow, Integer.valueOf(0)); } + private void sleep() { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + public void testCancelingChoiceSetSuccessfullyIfThreadIsRunning(){ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0)); presentChoiceSetOperation = new PresentChoiceSetOperation(internalInterface, choiceSet, InteractionMode.MANUAL_ONLY, null, null, choiceSetSelectionListener, Test.GENERAL_INTEGER); - executor.execute(presentChoiceSetOperation); + queue.add(presentChoiceSetOperation, false); - try { - executor.awaitTermination(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + sleep(); - assertTrue(presentChoiceSetOperation.isExecuting()); - assertFalse(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.IN_PROGRESS, presentChoiceSetOperation.getState()); choiceSet.cancel(); Answer<Void> cancelInteractionAnswer = new Answer<Void>() { @@ -170,22 +177,16 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { verify(internalInterface, times(1)).sendRPC(any(CancelInteraction.class)); verify(internalInterface, times(1)).sendRPC(any(PerformInteraction.class)); - assertTrue(presentChoiceSetOperation.isExecuting()); - assertFalse(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.IN_PROGRESS, presentChoiceSetOperation.getState()); } public void testCancelingChoiceSetUnsuccessfullyIfThreadIsRunning(){ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0)); presentChoiceSetOperation = new PresentChoiceSetOperation(internalInterface, choiceSet, InteractionMode.MANUAL_ONLY, null, null, choiceSetSelectionListener, Test.GENERAL_INTEGER); - executor.execute(presentChoiceSetOperation); - try { - executor.awaitTermination(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + queue.add(presentChoiceSetOperation, false); + sleep(); - assertTrue(presentChoiceSetOperation.isExecuting()); - assertFalse(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.IN_PROGRESS, presentChoiceSetOperation.getState()); choiceSet.cancel(); Answer<Void> cancelInteractionAnswer = new Answer<Void>() { @@ -209,9 +210,7 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { verify(internalInterface, times(1)).sendRPC(any(CancelInteraction.class)); verify(internalInterface, times(1)).sendRPC(any(PerformInteraction.class)); - assertTrue(presentChoiceSetOperation.isExecuting()); - assertFalse(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.IN_PROGRESS, presentChoiceSetOperation.getState()); } public void testCancelingChoiceSetIfThreadHasFinished(){ @@ -219,37 +218,27 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { presentChoiceSetOperation = new PresentChoiceSetOperation(internalInterface, choiceSet, InteractionMode.MANUAL_ONLY, null, null, choiceSetSelectionListener, Test.GENERAL_INTEGER); presentChoiceSetOperation.finishOperation(); - assertFalse(presentChoiceSetOperation.isExecuting()); - assertTrue(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.FINISHED, presentChoiceSetOperation.getState()); choiceSet.cancel(); verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); - assertFalse(presentChoiceSetOperation.isExecuting()); - assertTrue(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.FINISHED, presentChoiceSetOperation.getState()); } public void testCancelingChoiceSetIfThreadHasNotYetRun(){ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0)); presentChoiceSetOperation = new PresentChoiceSetOperation(internalInterface, choiceSet, InteractionMode.MANUAL_ONLY, null, null, choiceSetSelectionListener, Test.GENERAL_INTEGER); - assertFalse(presentChoiceSetOperation.isExecuting()); - assertFalse(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.BLOCKED, presentChoiceSetOperation.getState()); choiceSet.cancel(); // Once the operation has started - executor.execute(presentChoiceSetOperation); - try { - executor.awaitTermination(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + queue.add(presentChoiceSetOperation, false); + sleep(); - assertFalse(presentChoiceSetOperation.isExecuting()); - assertTrue(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.CANCELED, presentChoiceSetOperation.getState()); // Make sure neither a `CancelInteraction` or `PerformInteraction` RPC is ever sent verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); @@ -260,14 +249,10 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { // Cancel Interaction is only supported on RPC specs v.6.0.0+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(5, 3)); presentChoiceSetOperation = new PresentChoiceSetOperation(internalInterface, choiceSet, InteractionMode.MANUAL_ONLY, null, null, choiceSetSelectionListener, Test.GENERAL_INTEGER); - executor.execute(presentChoiceSetOperation); - try { - executor.awaitTermination(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + queue.add(presentChoiceSetOperation, false); + sleep(); - assertTrue(presentChoiceSetOperation.isExecuting()); - assertFalse(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.IN_PROGRESS, presentChoiceSetOperation.getState()); choiceSet.cancel(); @@ -280,23 +265,17 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(5, 3)); presentChoiceSetOperation = new PresentChoiceSetOperation(internalInterface, choiceSet, InteractionMode.MANUAL_ONLY, null, null, choiceSetSelectionListener, Test.GENERAL_INTEGER); - assertFalse(presentChoiceSetOperation.isExecuting()); - assertFalse(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.BLOCKED, presentChoiceSetOperation.getState()); choiceSet.cancel(); verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); // Once the operation has started - executor.execute(presentChoiceSetOperation); - try { - executor.awaitTermination(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + queue.add(presentChoiceSetOperation, false); + sleep(); - assertFalse(presentChoiceSetOperation.isExecuting()); - assertTrue(presentChoiceSetOperation.isFinished()); - assertFalse(presentChoiceSetOperation.isCancelled()); + assertEquals(Task.CANCELED, presentChoiceSetOperation.getState()); // Make sure neither a `CancelInteraction` or `PerformInteraction` RPC is ever sent verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); 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 486a1c361..72fd81bbc 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 @@ -35,6 +35,9 @@ package com.smartdevicelink.managers.screen.choiceset; +import com.livio.taskmaster.Queue; +import com.livio.taskmaster.Task; +import com.livio.taskmaster.Taskmaster; import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCResponse; @@ -53,10 +56,6 @@ 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; @@ -71,7 +70,8 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { private KeyboardListener keyboardListener; private ISdl internalInterface; - private ExecutorService executor; + private Taskmaster taskmaster; + private Queue queue; @Override public void setUp() throws Exception{ @@ -95,7 +95,9 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { }; doAnswer(setGlobalPropertiesAnswer).when(internalInterface).sendRPC(any(SetGlobalProperties.class)); - executor = Executors.newCachedThreadPool(); + taskmaster = new Taskmaster.Builder().build(); + queue = taskmaster.createQueue("test", 100, false); + taskmaster.start(); } @Override @@ -123,17 +125,21 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { assertEquals(pi.getCancelID(), Test.GENERAL_INTEGER); } + private void sleep() { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + 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(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + queue.add(presentKeyboardOperation, false); + sleep(); - assertTrue(presentKeyboardOperation.isExecuting()); - assertFalse(presentKeyboardOperation.isFinished()); - assertFalse(presentKeyboardOperation.isCancelled()); + assertEquals(Task.IN_PROGRESS, presentKeyboardOperation.getState()); presentKeyboardOperation.dismissKeyboard(); Answer<Void> cancelInteractionAnswer = new Answer<Void>() { @@ -157,18 +163,14 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { 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()); + assertEquals(Task.IN_PROGRESS, presentKeyboardOperation.getState()); } 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(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + queue.add(presentKeyboardOperation, false); + sleep(); presentKeyboardOperation.dismissKeyboard(); Answer<Void> cancelInteractionAnswer = new Answer<Void>() { @@ -192,9 +194,7 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { 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()); + assertEquals(Task.IN_PROGRESS, presentKeyboardOperation.getState()); } public void testCancelingKeyboardIfThreadHasFinished(){ @@ -202,37 +202,27 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { presentKeyboardOperation = new PresentKeyboardOperation(internalInterface, null, "Test", null, null, Test.GENERAL_INTEGER); presentKeyboardOperation.finishOperation(); - assertFalse(presentKeyboardOperation.isExecuting()); - assertTrue(presentKeyboardOperation.isFinished()); - assertFalse(presentKeyboardOperation.isCancelled()); + assertEquals(Task.FINISHED, presentKeyboardOperation.getState()); presentKeyboardOperation.dismissKeyboard(); verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); - assertFalse(presentKeyboardOperation.isExecuting()); - assertTrue(presentKeyboardOperation.isFinished()); - assertFalse(presentKeyboardOperation.isCancelled()); + assertEquals(Task.FINISHED, presentKeyboardOperation.getState()); } 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()); + assertEquals(Task.BLOCKED, presentKeyboardOperation.getState()); presentKeyboardOperation.dismissKeyboard(); // Once the operation has started - executor.execute(presentKeyboardOperation); - try { - executor.awaitTermination(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + queue.add(presentKeyboardOperation, false); + sleep(); - assertFalse(presentKeyboardOperation.isExecuting()); - assertTrue(presentKeyboardOperation.isFinished()); - assertFalse(presentKeyboardOperation.isCancelled()); + assertEquals(Task.CANCELED, presentKeyboardOperation.getState()); // Make sure neither a `CancelInteraction` or `PerformInteraction` RPC is ever sent verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); @@ -243,14 +233,10 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { // 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(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + queue.add(presentKeyboardOperation, false); + sleep(); - assertTrue(presentKeyboardOperation.isExecuting()); - assertFalse(presentKeyboardOperation.isFinished()); - assertFalse(presentKeyboardOperation.isCancelled()); + assertEquals(Task.IN_PROGRESS, presentKeyboardOperation.getState()); presentKeyboardOperation.dismissKeyboard(); @@ -263,23 +249,17 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { 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()); + assertEquals(Task.BLOCKED, presentKeyboardOperation.getState()); presentKeyboardOperation.dismissKeyboard(); verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); // Once the operation has started - executor.execute(presentKeyboardOperation); - try { - executor.awaitTermination(1, TimeUnit.SECONDS); - } catch (InterruptedException e) {} + queue.add(presentKeyboardOperation, false); + sleep(); - assertFalse(presentKeyboardOperation.isExecuting()); - assertTrue(presentKeyboardOperation.isFinished()); - assertFalse(presentKeyboardOperation.isCancelled()); + assertEquals(Task.CANCELED, presentKeyboardOperation.getState()); // Make sure neither a `CancelInteraction` or `PerformInteraction` RPC is ever sent verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java index e28cd9a00..ae5e676df 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java @@ -2,6 +2,7 @@ package com.smartdevicelink.test.proxy; import android.util.SparseArray; +import com.livio.taskmaster.Taskmaster; import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.managers.ManagerUtility; import com.smartdevicelink.protocol.enums.FunctionID; @@ -1069,5 +1070,10 @@ public class SystemCapabilityManagerTests extends AndroidTestCase2 { @Override public void startRPCEncryption() {} + + @Override + public Taskmaster getTaskmaster() { + return null; + } } } |