55
66import com .smartdevicelink .AndroidTestCase2 ;
77import com .smartdevicelink .managers .BaseSubManager ;
8+ import com .smartdevicelink .managers .ManagerUtility ;
89import com .smartdevicelink .managers .file .FileManager ;
910import com .smartdevicelink .managers .file .filetypes .SdlArtwork ;
1011import com .smartdevicelink .proxy .interfaces .ISdl ;
2122import org .json .JSONException ;
2223
2324import java .util .ArrayList ;
25+ import java .util .Arrays ;
2426import java .util .List ;
2527
2628import static org .mockito .Mockito .mock ;
@@ -90,6 +92,16 @@ private WindowCapability getWindowCapability(int numberOfMainFields){
9092 return windowCapability ;
9193 }
9294
95+ /**
96+ * Used to simulate WindowCapability having no capabilities set
97+ * @return windowCapability that has no capabilities set
98+ */
99+ private WindowCapability getNullVarWindowCapability () {
100+
101+ WindowCapability windowCapability = new WindowCapability ();
102+ return windowCapability ;
103+ }
104+
93105 public void testInstantiation (){
94106
95107 assertNull (textAndGraphicManager .getTextField1 ());
@@ -117,17 +129,21 @@ public void testInstantiation(){
117129 assertNotNull (textAndGraphicManager .getBlankArtwork ());
118130 }
119131
132+ /**
133+ * Test getting number of lines available to be set based off of windowCapability
134+ */
120135 public void testGetMainLines (){
121136
122137 // We want to test that the looping works. By default, it will return 4 if display cap is null
138+ textAndGraphicManager .defaultMainWindowCapability = getNullVarWindowCapability ();
123139
124140 // Null test
125- assertEquals (textAndGraphicManager . getNumberOfLines (), 4 );
141+ assertEquals (0 , ManagerUtility . WindowCapabilityUtility . getMaxNumberOfMainFieldLines ( textAndGraphicManager . defaultMainWindowCapability ) );
126142
127143 // The tests.java class has an example of this, but we must build it to do what
128144 // we need it to do. Build display cap w/ 3 main fields and test that it returns 3
129145 textAndGraphicManager .defaultMainWindowCapability = getWindowCapability (3 );
130- assertEquals (textAndGraphicManager . getNumberOfLines ( ), 3 );
146+ assertEquals (ManagerUtility . WindowCapabilityUtility . getMaxNumberOfMainFieldLines ( textAndGraphicManager . defaultMainWindowCapability ), 3 );
131147 }
132148
133149 public void testAssemble1Line (){
@@ -374,8 +390,141 @@ public void testAssemble4Lines() {
374390
375391 Show inputShow = new Show ();
376392
377- // Force it to return display with support for only 4 lines of text
378393 textAndGraphicManager .defaultMainWindowCapability = getWindowCapability (4 );
394+ TextField tx1 = new TextField ();
395+ TextField tx2 = new TextField ();
396+ TextField tx3 = new TextField ();
397+ TextField tx4 = new TextField ();
398+ TextField tx5 = new TextField ();
399+ TextField tx6 = new TextField ();
400+
401+ tx1 .setName (TextFieldName .mainField1 );
402+ tx2 .setName (TextFieldName .mainField2 );
403+ tx3 .setName (TextFieldName .mainField3 );
404+ tx4 .setName (TextFieldName .mainField4 );
405+ tx5 .setName (TextFieldName .mediaTrack );
406+ tx6 .setName (TextFieldName .templateTitle );
407+
408+ List <TextField > textFieldNames = Arrays .asList (tx1 ,tx2 ,tx3 ,tx4 ,tx5 ,tx6 );
409+ textAndGraphicManager .defaultMainWindowCapability .setTextFields (textFieldNames );
410+
411+ textAndGraphicManager .setMediaTrackTextField ("HI" );
412+ textAndGraphicManager .setTitle ("bye" );
413+
414+ // Force it to return display with support for only 4 lines of text
415+
416+ textAndGraphicManager .setTextField1 ("It is" );
417+ textAndGraphicManager .setTextField1Type (MetadataType .HUMIDITY );
418+
419+ Show assembledShow = textAndGraphicManager .assembleShowText (inputShow );
420+
421+ assertEquals (assembledShow .getMainField1 (), "It is" );
422+ assertEquals (assembledShow .getMainField2 (), "" );
423+ assertEquals (assembledShow .getMainField3 (), "" );
424+ assertEquals (assembledShow .getMainField4 (), "" );
425+ assertEquals (assembledShow .getMediaTrack (), "HI" );
426+ assertEquals (assembledShow .getTemplateTitle (), "bye" );
427+
428+ // test tags
429+ MetadataTags tags = assembledShow .getMetadataTags ();
430+ List <MetadataType > tagsList = new ArrayList <>();
431+ tagsList .add (MetadataType .HUMIDITY );
432+ assertEquals (tags .getMainField1 (), tagsList );
433+
434+ textAndGraphicManager .setTextField2 ("Wednesday" );
435+ textAndGraphicManager .setTextField2Type (MetadataType .CURRENT_TEMPERATURE );
436+
437+ assembledShow = textAndGraphicManager .assembleShowText (inputShow );
438+ assertEquals (assembledShow .getMainField1 (), "It is" );
439+ assertEquals (assembledShow .getMainField2 (), "Wednesday" );
440+ assertEquals (assembledShow .getMainField3 (), "" );
441+ assertEquals (assembledShow .getMainField4 (), "" );
442+
443+ // test tags
444+ tags = assembledShow .getMetadataTags ();
445+ tagsList = new ArrayList <>();
446+ List <MetadataType > tagsList2 = new ArrayList <>();
447+ tagsList .add (MetadataType .HUMIDITY );
448+ tagsList2 .add (MetadataType .CURRENT_TEMPERATURE );
449+ assertEquals (tags .getMainField1 (), tagsList );
450+ assertEquals (tags .getMainField2 (), tagsList2 );
451+
452+ textAndGraphicManager .setTextField3 ("My" );
453+ textAndGraphicManager .setTextField3Type (MetadataType .MEDIA_ALBUM );
454+
455+ assembledShow = textAndGraphicManager .assembleShowText (inputShow );
456+ assertEquals (assembledShow .getMainField1 (), "It is" );
457+ assertEquals (assembledShow .getMainField2 (), "Wednesday" );
458+ assertEquals (assembledShow .getMainField3 (), "My" );
459+ assertEquals (assembledShow .getMainField4 (), "" );
460+
461+ // test tags
462+ tags = assembledShow .getMetadataTags ();
463+ tagsList = new ArrayList <>();
464+ tagsList2 = new ArrayList <>();
465+ List <MetadataType > tagsList3 = new ArrayList <>();
466+ tagsList .add (MetadataType .HUMIDITY );
467+ tagsList2 .add (MetadataType .CURRENT_TEMPERATURE );
468+ tagsList3 .add (MetadataType .MEDIA_ALBUM );
469+ assertEquals (tags .getMainField1 (), tagsList );
470+ assertEquals (tags .getMainField2 (), tagsList2 );
471+ assertEquals (tags .getMainField3 (), tagsList3 );
472+
473+ textAndGraphicManager .setTextField4 ("Dudes" );
474+ textAndGraphicManager .setTextField4Type (MetadataType .MEDIA_STATION );
475+
476+ assembledShow = textAndGraphicManager .assembleShowText (inputShow );
477+ assertEquals (assembledShow .getMainField1 (), "It is" );
478+ assertEquals (assembledShow .getMainField2 (), "Wednesday" );
479+ assertEquals (assembledShow .getMainField3 (), "My" );
480+ assertEquals (assembledShow .getMainField4 (), "Dudes" );
481+
482+ // test tags
483+ tags = assembledShow .getMetadataTags ();
484+ tagsList = new ArrayList <>();
485+ tagsList2 = new ArrayList <>();
486+ tagsList3 = new ArrayList <>();
487+ List <MetadataType > tagsList4 = new ArrayList <>();
488+ tagsList .add (MetadataType .HUMIDITY );
489+ tagsList2 .add (MetadataType .CURRENT_TEMPERATURE );
490+ tagsList3 .add (MetadataType .MEDIA_ALBUM );
491+ tagsList4 .add (MetadataType .MEDIA_STATION );
492+ assertEquals (tags .getMainField1 (), tagsList );
493+ assertEquals (tags .getMainField2 (), tagsList2 );
494+ assertEquals (tags .getMainField3 (), tagsList3 );
495+ assertEquals (tags .getMainField4 (), tagsList4 );
496+
497+ // try just setting line 1 and 4
498+ textAndGraphicManager .setTextField2 (null );
499+ textAndGraphicManager .setTextField3 (null );
500+ textAndGraphicManager .setTextField2Type (null );
501+ textAndGraphicManager .setTextField3Type (null );
502+
503+ assembledShow = textAndGraphicManager .assembleShowText (inputShow );
504+ assertEquals (assembledShow .getMainField1 (), "It is" );
505+ assertEquals (assembledShow .getMainField2 (), "" );
506+ assertEquals (assembledShow .getMainField3 (), "" );
507+ assertEquals (assembledShow .getMainField4 (), "Dudes" );
508+
509+ // test tags
510+ tags = assembledShow .getMetadataTags ();
511+ tagsList = new ArrayList <>();
512+ tagsList4 = new ArrayList <>();
513+ tagsList .add (MetadataType .HUMIDITY );
514+ tagsList4 .add (MetadataType .MEDIA_STATION );
515+ assertEquals (tags .getMainField1 (), tagsList );
516+ assertEquals (tags .getMainField4 (), tagsList4 );
517+ }
518+
519+ /**
520+ * Testing if WindowCapability is null, TextFields should still update.
521+ */
522+ public void testAssemble4LinesNullWindowCapability () {
523+
524+ Show inputShow = new Show ();
525+
526+ textAndGraphicManager .setMediaTrackTextField ("HI" );
527+ textAndGraphicManager .setTitle ("bye" );
379528
380529 textAndGraphicManager .setTextField1 ("It is" );
381530 textAndGraphicManager .setTextField1Type (MetadataType .HUMIDITY );
@@ -386,6 +535,8 @@ public void testAssemble4Lines() {
386535 assertEquals (assembledShow .getMainField2 (), "" );
387536 assertEquals (assembledShow .getMainField3 (), "" );
388537 assertEquals (assembledShow .getMainField4 (), "" );
538+ assertEquals (assembledShow .getMediaTrack (), "HI" );
539+ assertEquals (assembledShow .getTemplateTitle (), "bye" );
389540
390541 // test tags
391542 MetadataTags tags = assembledShow .getMetadataTags ();
0 commit comments