2727import com .smartdevicelink .proxy .rpc .enums .FileType ;
2828import com .smartdevicelink .proxy .rpc .enums .ImageFieldName ;
2929import com .smartdevicelink .proxy .rpc .enums .SpeechCapabilities ;
30+ import com .smartdevicelink .proxy .rpc .enums .StaticIconName ;
3031import com .smartdevicelink .proxy .rpc .enums .TextFieldName ;
3132import com .smartdevicelink .test .TestValues ;
3233
4243
4344import static androidx .test .platform .app .InstrumentationRegistry .getInstrumentation ;
4445import static junit .framework .TestCase .assertEquals ;
45- import static junit .framework .TestCase .assertTrue ;
4646import static org .mockito .ArgumentMatchers .any ;
4747import static org .mockito .Mockito .doAnswer ;
4848import static org .mockito .Mockito .mock ;
@@ -167,7 +167,7 @@ public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEve
167167 builder .setShowWaitIndicator (true );
168168 alertView = builder .build ();
169169
170- defaultMainWindowCapability = getWindowCapability (3 );
170+ defaultMainWindowCapability = getWindowCapability (3 , true );
171171 speechCapabilities = new ArrayList <SpeechCapabilities >();
172172 speechCapabilities .add (SpeechCapabilities .FILE );
173173 alertCompletionListener = new AlertCompletionListener () {
@@ -186,13 +186,13 @@ public void testPresentAlertTruncatedText() {
186186 // Same response works for uploading artworks as it does for files
187187
188188 when (internalInterface .getSdlMsgVersion ()).thenReturn (new SdlMsgVersion (6 , 0 ));
189- WindowCapability windowCapability = getWindowCapability (1 );
189+ WindowCapability windowCapability = getWindowCapability (1 , true );
190190 PresentAlertOperation presentAlertOperation = new PresentAlertOperation (internalInterface , alertView , windowCapability , speechCapabilities , fileManager , 1 , alertCompletionListener , alertSoftButtonClearListener );
191191 Alert alert = presentAlertOperation .alertRpc ();
192192
193193 assertEquals (alert .getAlertText1 (), alertView .getText () + " - " + alertView .getSecondaryText () + " - " + alertView .getTertiaryText ());
194194
195- windowCapability = getWindowCapability (2 );
195+ windowCapability = getWindowCapability (2 , true );
196196
197197 presentAlertOperation = new PresentAlertOperation (internalInterface , alertView , windowCapability , speechCapabilities , fileManager , 1 , alertCompletionListener , alertSoftButtonClearListener );
198198 alert = presentAlertOperation .alertRpc ();
@@ -258,7 +258,23 @@ public void testPresentAlertNoImages() {
258258 verify (fileManager , times (1 )).uploadArtworks (any (List .class ), any (MultipleFileCompletionListener .class ));
259259 verify (internalInterface , times (1 )).sendRPC (any (Alert .class ));
260260 }
261+ @ Test
262+ public void testPresentStaticIcon () {
263+ doAnswer (onAlertSuccess ).when (internalInterface ).sendRPC (any (Alert .class ));
264+ // Same response works for uploading artworks as it does for files
265+ when (internalInterface .getSdlMsgVersion ()).thenReturn (new SdlMsgVersion (6 , 0 ));
266+ when (fileManager .fileNeedsUpload (any (SdlFile .class ))).thenReturn (false );
267+
268+ alertView .setIcon (new SdlArtwork (StaticIconName .LEFT ));
269+ PresentAlertOperation presentAlertOperationStaticIcon = new PresentAlertOperation (internalInterface , alertView , defaultMainWindowCapability , speechCapabilities , fileManager , 1 , alertCompletionListener , alertSoftButtonClearListener );
270+
271+ // Test Images need to be uploaded, sending text and uploading images
272+ presentAlertOperationStaticIcon .onExecute ();
261273
274+ // Verifies that uploadArtworks gets called only with the fist presentAlertOperation.onExecute call
275+ verify (fileManager , times (0 )).uploadArtworks (any (List .class ), any (MultipleFileCompletionListener .class ));
276+ verify (internalInterface , times (1 )).sendRPC (any (Alert .class ));
277+ }
262278 @ Test
263279 public void testCancelOperation () {
264280 //Cancel right away
@@ -267,7 +283,7 @@ public void testCancelOperation() {
267283 verify (internalInterface , times (0 )).sendRPC (any (Alert .class ));
268284 }
269285
270- private WindowCapability getWindowCapability (int numberOfAlertFields ) {
286+ private WindowCapability getWindowCapability (int numberOfAlertFields , boolean supportsAlertIcon ) {
271287 TextField alertText1 = new TextField ();
272288 alertText1 .setName (TextFieldName .alertText1 );
273289 TextField alertText2 = new TextField ();
@@ -294,13 +310,13 @@ private WindowCapability getWindowCapability(int numberOfAlertFields) {
294310 WindowCapability windowCapability = new WindowCapability ();
295311 windowCapability .setTextFields (returnList );
296312
297- ImageField imageField = new ImageField ();
298- imageField . setName ( ImageFieldName . alertIcon );
299- List < ImageField > imageFieldList = new ArrayList <>( );
300- imageFieldList . add ( imageField );
301- windowCapability . setImageFields ( imageFieldList );
302-
303- windowCapability . setImageFields ( imageFieldList );
313+ if ( supportsAlertIcon ) {
314+ ImageField imageField = new ImageField ( );
315+ imageField . setName ( ImageFieldName . alertIcon );
316+ List < ImageField > imageFieldList = new ArrayList <>( );
317+ imageFieldList . add ( imageField );
318+ windowCapability . setImageFields ( imageFieldList );
319+ }
304320
305321 SoftButtonCapabilities softButtonCapabilities = new SoftButtonCapabilities ();
306322 softButtonCapabilities .setImageSupported (TestValues .GENERAL_BOOLEAN );
0 commit comments