11package com .smartdevicelink .managers .screen ;
22
33
4+ import com .livio .taskmaster .Taskmaster ;
45import com .smartdevicelink .AndroidTestCase2 ;
5- import com .smartdevicelink .managers .CompletionListener ;
66import com .smartdevicelink .managers .file .FileManager ;
77import com .smartdevicelink .managers .file .MultipleFileCompletionListener ;
88import com .smartdevicelink .managers .file .filetypes .SdlArtwork ;
99import com .smartdevicelink .protocol .enums .FunctionID ;
1010import com .smartdevicelink .proxy .interfaces .ISdl ;
11+ import com .smartdevicelink .proxy .interfaces .OnSystemCapabilityListener ;
12+ import com .smartdevicelink .proxy .rpc .DisplayCapability ;
1113import com .smartdevicelink .proxy .rpc .Image ;
1214import com .smartdevicelink .proxy .rpc .OnButtonEvent ;
1315import com .smartdevicelink .proxy .rpc .OnButtonPress ;
1416import com .smartdevicelink .proxy .rpc .OnHMIStatus ;
1517import com .smartdevicelink .proxy .rpc .Show ;
18+ import com .smartdevicelink .proxy .rpc .ShowResponse ;
1619import com .smartdevicelink .proxy .rpc .SoftButton ;
1720import com .smartdevicelink .proxy .rpc .SoftButtonCapabilities ;
1821import com .smartdevicelink .proxy .rpc .WindowCapability ;
1922import com .smartdevicelink .proxy .rpc .enums .FileType ;
2023import com .smartdevicelink .proxy .rpc .enums .HMILevel ;
2124import com .smartdevicelink .proxy .rpc .enums .ImageType ;
25+ import com .smartdevicelink .proxy .rpc .enums .Result ;
2226import com .smartdevicelink .proxy .rpc .enums .SoftButtonType ;
2327import com .smartdevicelink .proxy .rpc .enums .StaticIconName ;
2428import com .smartdevicelink .proxy .rpc .enums .SystemAction ;
29+ import com .smartdevicelink .proxy .rpc .enums .SystemCapabilityType ;
2530import com .smartdevicelink .proxy .rpc .listeners .OnRPCNotificationListener ;
2631import com .smartdevicelink .test .Validator ;
2732
3742import static org .mockito .ArgumentMatchers .eq ;
3843import static org .mockito .Mockito .doAnswer ;
3944import static org .mockito .Mockito .mock ;
45+ import static org .mockito .Mockito .when ;
4046
4147/**
4248 * This is a unit test class for the SmartDeviceLink library manager class :
@@ -47,10 +53,10 @@ public class SoftButtonManagerTests extends AndroidTestCase2 {
4753 private SoftButtonManager softButtonManager ;
4854 private boolean fileManagerUploadArtworksGotCalled ;
4955 private boolean internalInterfaceSendRPCGotCalled ;
50- private boolean softButtonMangerUpdateCompleted ;
5156 private int softButtonObject1Id = 1000 , softButtonObject2Id = 2000 ;
5257 private SoftButtonObject softButtonObject1 , softButtonObject2 ;
5358 private SoftButtonState softButtonState1 , softButtonState2 , softButtonState3 , softButtonState4 ;
59+ private Taskmaster taskmaster ;
5460
5561
5662 @ Override
@@ -74,6 +80,28 @@ public Void answer(InvocationOnMock invocation) {
7480 doAnswer (onHMIStatusAnswer ).when (internalInterface ).addOnRPCNotificationListener (eq (FunctionID .ON_HMI_STATUS ), any (OnRPCNotificationListener .class ));
7581
7682
83+ // When internalInterface.addOnSystemCapabilityListener(SystemCapabilityType.DISPLAYS, onSystemCapabilityListener) is called
84+ // inside SoftButtonManager, respond with a fake response to let the SoftButtonManager continue working.
85+ Answer <Void > onSystemCapabilityAnswer = new Answer <Void >() {
86+ @ Override
87+ public Void answer (InvocationOnMock invocation ) {
88+ Object [] args = invocation .getArguments ();
89+ OnSystemCapabilityListener onSystemCapabilityListener = (OnSystemCapabilityListener ) args [1 ];
90+ SoftButtonCapabilities softButtonCapabilities = new SoftButtonCapabilities ();
91+ softButtonCapabilities .setImageSupported (true );
92+ softButtonCapabilities .setTextSupported (true );
93+ WindowCapability windowCapability = new WindowCapability ();
94+ windowCapability .setSoftButtonCapabilities (Collections .singletonList (softButtonCapabilities ));
95+ DisplayCapability displayCapability = new DisplayCapability ();
96+ displayCapability .setWindowCapabilities (Arrays .asList (windowCapability ));
97+ List <DisplayCapability > capabilities = Arrays .asList (displayCapability );
98+ onSystemCapabilityListener .onCapabilityRetrieved (capabilities );
99+ return null ;
100+ }
101+ };
102+ doAnswer (onSystemCapabilityAnswer ).when (internalInterface ).addOnSystemCapabilityListener (eq (SystemCapabilityType .DISPLAYS ), any (OnSystemCapabilityListener .class ));
103+
104+
77105 // When fileManager.uploadArtworks() is called inside the SoftButtonManager, respond with
78106 // a fake onComplete() callback to let the SoftButtonManager continue working.
79107 FileManager fileManager = mock (FileManager .class );
@@ -91,6 +119,9 @@ public Void answer(InvocationOnMock invocation) {
91119
92120
93121 // Create softButtonManager
122+ taskmaster = new Taskmaster .Builder ().build ();
123+ taskmaster .start ();
124+ when (internalInterface .getTaskmaster ()).thenReturn (taskmaster );
94125 softButtonManager = new SoftButtonManager (internalInterface , fileManager );
95126
96127
@@ -104,10 +135,10 @@ public Void answer(InvocationOnMock invocation) {
104135 Object [] args = invocation .getArguments ();
105136 Show show = (Show ) args [0 ];
106137
107- show .getOnRPCResponseListener ().onResponse (0 , null );
138+ show .getOnRPCResponseListener ().onResponse (0 , new ShowResponse ( true , Result . SUCCESS ) );
108139
109140 assertEquals (show .getMainField1 (), softButtonManager .getCurrentMainField1 ());
110- assertEquals (show .getSoftButtons ().size (), softButtonManager .createSoftButtonsForCurrentState ().size ());
141+ assertEquals (show .getSoftButtons ().size (), softButtonManager .getSoftButtonObjects ().size ());
111142
112143 return null ;
113144 }
@@ -131,42 +162,39 @@ public void tearDown() throws Exception {
131162 super .tearDown ();
132163 }
133164
165+ private void sleep () {
166+ try {
167+ Thread .sleep (100 );
168+ } catch (InterruptedException e ) {
169+ e .printStackTrace ();
170+ }
171+ }
172+
134173 public void testSoftButtonManagerUpdate () {
135174 // Reset the boolean variables
136175 fileManagerUploadArtworksGotCalled = false ;
137176 internalInterfaceSendRPCGotCalled = false ;
138- softButtonMangerUpdateCompleted = false ;
139-
140- SoftButtonCapabilities softCap = new SoftButtonCapabilities ();
141- softCap .setImageSupported (true );
142- WindowCapability defaultCap = new WindowCapability ();
143- defaultCap .setSoftButtonCapabilities (Collections .singletonList (softCap ));
144- softButtonManager .defaultMainWindowCapability = defaultCap ;
145177
146178
147179 // Test batch update
148180 softButtonManager .setBatchUpdates (true );
149181 List <SoftButtonObject > softButtonObjects = Arrays .asList (softButtonObject1 , softButtonObject2 );
150182 softButtonManager .setSoftButtonObjects (Arrays .asList (softButtonObject1 , softButtonObject2 ));
151183 softButtonManager .setBatchUpdates (false );
152- softButtonManager .update (new CompletionListener () {
153- @ Override
154- public void onComplete (boolean success ) {
155- softButtonMangerUpdateCompleted = true ;
156- }
157- });
158184
159185
160186 // Test single update, setCurrentMainField1, and transitionToNextState
161187 softButtonManager .setCurrentMainField1 ("It is Wednesday my dudes!" );
162188 softButtonObject1 .transitionToNextState ();
163189
164190
165- // Check that everything got called as expected
191+ // Sleep to give time to Taskmaster to run the operations
192+ sleep ();
166193
167- assertTrue ("FileManager.uploadArtworks() did get called" , fileManagerUploadArtworksGotCalled );
194+
195+ // Check that everything got called as expected
196+ assertTrue ("FileManager.uploadArtworks() did not get called" , fileManagerUploadArtworksGotCalled );
168197 assertTrue ("InternalInterface.sendRPC() did not get called" , internalInterfaceSendRPCGotCalled );
169- assertTrue ("SoftButtonManger update onComplete() did not get called" , softButtonMangerUpdateCompleted );
170198
171199
172200 // Test getSoftButtonObjects
0 commit comments