3838
3939import com .livio .taskmaster .Taskmaster ;
4040import com .smartdevicelink .managers .BaseSubManager ;
41+ import com .smartdevicelink .managers .CompletionListener ;
4142import com .smartdevicelink .managers .ISdl ;
4243import com .smartdevicelink .managers .file .FileManager ;
43- import com .smartdevicelink .proxy .rpc .ImageField ;
4444import com .smartdevicelink .proxy .rpc .KeyboardCapabilities ;
4545import com .smartdevicelink .proxy .rpc .KeyboardLayoutCapability ;
4646import com .smartdevicelink .proxy .rpc .KeyboardProperties ;
4747import com .smartdevicelink .proxy .rpc .SdlMsgVersion ;
48- import com .smartdevicelink .proxy .rpc .TextField ;
4948import com .smartdevicelink .proxy .rpc .WindowCapability ;
5049import com .smartdevicelink .proxy .rpc .enums .HMILevel ;
51- import com .smartdevicelink .proxy .rpc .enums .ImageFieldName ;
5250import com .smartdevicelink .proxy .rpc .enums .KeyboardInputMask ;
5351import com .smartdevicelink .proxy .rpc .enums .KeyboardLayout ;
5452import com .smartdevicelink .proxy .rpc .enums .KeypressMode ;
5553import com .smartdevicelink .proxy .rpc .enums .Language ;
5654import com .smartdevicelink .proxy .rpc .enums .SystemContext ;
57- import com .smartdevicelink .proxy .rpc .enums .TextFieldName ;
5855import com .smartdevicelink .proxy .rpc .enums .TriggerSource ;
59- import com .smartdevicelink .test .TestValues ;
6056
6157import org .junit .After ;
6258import org .junit .Before ;
6864import java .util .Arrays ;
6965import java .util .Collections ;
7066import java .util .HashSet ;
71- import java .util .LinkedHashSet ;
72- import java .util .List ;
7367
7468import static junit .framework .TestCase .assertEquals ;
7569import static junit .framework .TestCase .assertFalse ;
7670import static junit .framework .TestCase .assertNotNull ;
77- import static junit .framework .TestCase .assertNotSame ;
7871import static junit .framework .TestCase .assertNull ;
7972import static junit .framework .TestCase .assertTrue ;
8073import static org .mockito .Mockito .doReturn ;
@@ -103,16 +96,12 @@ public void setUp() throws Exception {
10396 assertEquals (csm .getState (), BaseSubManager .SETTING_UP );
10497 assertEquals (csm .currentSystemContext , SystemContext .SYSCTXT_MAIN );
10598 assertEquals (csm .currentHMILevel , HMILevel .HMI_NONE );
106- assertEquals (csm .choiceCellIdMin , 1 );
107- assertEquals (csm .nextChoiceId , 1 );
10899 assertFalse (csm .isVROptional );
109100 assertNotNull (csm .fileManager );
110101 assertNotNull (csm .preloadedChoices );
111- assertNotNull (csm .pendingPreloadChoices );
112102 assertNotNull (csm .transactionQueue );
113103 assertNotNull (csm .hmiListener );
114104 assertNotNull (csm .onDisplayCapabilityListener );
115- assertNull (csm .pendingPresentOperation );
116105 }
117106
118107 @ After
@@ -123,11 +112,8 @@ public void tearDown() throws Exception {
123112 assertNull (csm .currentHMILevel );
124113 assertNull (csm .currentSystemContext );
125114 assertNull (csm .defaultMainWindowCapability );
126- assertNull (csm .pendingPresentationSet );
127- assertNull (csm .pendingPresentOperation );
128115
129116 assertEquals (csm .transactionQueue .getTasksAsList ().size (), 0 );
130- assertEquals (csm .nextChoiceId , 1 );
131117
132118 assertFalse (csm .isVROptional );
133119
@@ -160,12 +146,6 @@ public void onError(String error) {
160146 ChoiceSet choiceSet1 = new ChoiceSet ("test" , Collections .<ChoiceCell >emptyList (), choiceSetSelectionListener );
161147 assertFalse (csm .setUpChoiceSet (choiceSet1 ));
162148
163- // Identical cells will not be allowed
164- ChoiceCell cell1 = new ChoiceCell ("test" );
165- ChoiceCell cell2 = new ChoiceCell ("test" );
166- ChoiceSet choiceSet2 = new ChoiceSet ("test" , Arrays .asList (cell1 , cell2 ), choiceSetSelectionListener );
167- assertFalse (csm .setUpChoiceSet (choiceSet2 ));
168-
169149 // cells that have duplicate text will be allowed if there is another property to make them unique because a unique name will be assigned and used
170150 ChoiceCell cell3 = new ChoiceCell ("test" );
171151 cell3 .setSecondaryText ("text 1" );
@@ -208,103 +188,56 @@ public void testFindIfPresent() {
208188 }
209189
210190 @ Test
211- public void testUpdateIdsOnChoices () {
212-
191+ public void preloadChoicesAddsToQueue () {
213192 ChoiceCell cell1 = new ChoiceCell ("test" );
214193 ChoiceCell cell2 = new ChoiceCell ("test2" );
215194 ChoiceCell cell3 = new ChoiceCell ("test3" );
216- LinkedHashSet <ChoiceCell > cellSet = new LinkedHashSet <>();
195+ ArrayList <ChoiceCell > cellSet = new ArrayList <>();
217196 cellSet .add (cell1 );
218197 cellSet .add (cell2 );
219198 cellSet .add (cell3 );
220- // Cells are initially set to MAX_ID
221- assertEquals (cell1 .getChoiceId (), 2000000000 );
222- assertEquals (cell2 .getChoiceId (), 2000000000 );
223- assertEquals (cell3 .getChoiceId (), 2000000000 );
224- csm .updateIdsOnChoices (cellSet );
225- // We are looking for unique IDs
226- assertNotSame (cell1 .getChoiceId (), 2000000000 );
227- assertNotSame (cell2 .getChoiceId (), 2000000000 );
228- assertNotSame (cell3 .getChoiceId (), 2000000000 );
229- }
199+ csm .preloadChoices (cellSet , new CompletionListener () {
200+ @ Override
201+ public void onComplete (boolean success ) {
230202
231- @ Test
232- public void testAddUniqueNamesToCells () {
233- ChoiceCell cell1 = new ChoiceCell ("McDonalds" , "1 mile away" , null , null , null , null );
234- ChoiceCell cell2 = new ChoiceCell ("McDonalds" , "2 mile away" , null , null , null , null );
235- ChoiceCell cell3 = new ChoiceCell ("Starbucks" , "3 mile away" , null , null , null , null );
236- ChoiceCell cell4 = new ChoiceCell ("McDonalds" , "4 mile away" , null , null , null , null );
237- ChoiceCell cell5 = new ChoiceCell ("Starbucks" , "5 mile away" , null , null , null , null );
238- ChoiceCell cell6 = new ChoiceCell ("Meijer" , "6 mile away" , null , null , null , null );
239- List <ChoiceCell > cellList = new ArrayList <>();
240-
241- cellList .add (cell1 );
242- cellList .add (cell2 );
243- cellList .add (cell3 );
244- cellList .add (cell4 );
245- cellList .add (cell5 );
246- cellList .add (cell6 );
247-
248- csm .addUniqueNamesToCells (cellList );
249-
250- assertEquals (cell1 .getUniqueText (), "McDonalds" );
251- assertEquals (cell2 .getUniqueText (), "McDonalds (2)" );
252- assertEquals (cell3 .getUniqueText (), "Starbucks" );
253- assertEquals (cell4 .getUniqueText (), "McDonalds (3)" );
254- assertEquals (cell5 .getUniqueText (), "Starbucks (2)" );
255- assertEquals (cell6 .getUniqueText (), "Meijer" );
203+ }
204+ });
205+ assertEquals (csm .transactionQueue .getTasksAsList ().size (), 1 );
256206 }
257207
258208 @ Test
259- public void testChoicesToBeRemovedFromPendingWithArray () {
260-
261- ChoiceCell cell1 = new ChoiceCell ("test" );
262- ChoiceCell cell2 = new ChoiceCell ("test2" );
263- ChoiceCell cell3 = new ChoiceCell ("test3" );
264-
265- HashSet <ChoiceCell > pendingPreloadSet = new HashSet <>();
266- pendingPreloadSet .add (cell1 );
267- pendingPreloadSet .add (cell2 );
268- pendingPreloadSet .add (cell3 );
269-
270- csm .pendingPreloadChoices .clear ();
271- csm .pendingPreloadChoices = pendingPreloadSet ;
272-
273- List <ChoiceCell > choices = new ArrayList <>();
274- choices .add (cell2 );
275-
276- HashSet <ChoiceCell > returnedChoices = csm .choicesToBeRemovedFromPendingWithArray (choices );
209+ public void preloadChoicesQueueEmptyWhenNoChoiceCells () {
210+ ArrayList <ChoiceCell > cellSet = new ArrayList <>();
211+ csm .preloadChoices (cellSet , new CompletionListener () {
212+ @ Override
213+ public void onComplete (boolean success ) {
277214
278- assertEquals (returnedChoices .size (), 1 );
279- for (ChoiceCell cell : returnedChoices ) {
280- assertEquals (cell .getText (), "test2" );
281- }
215+ }
216+ });
217+ assertEquals (csm .transactionQueue .getTasksAsList ().size (), 0 );
282218 }
283219
284220 @ Test
285- public void testChoicesToBeUploadedWithArray () {
286-
221+ public void testPreloadChoicesQueueEmptyIfFileManagerNull () {
287222 ChoiceCell cell1 = new ChoiceCell ("test" );
288223 ChoiceCell cell2 = new ChoiceCell ("test2" );
289224 ChoiceCell cell3 = new ChoiceCell ("test3" );
225+ ArrayList <ChoiceCell > cellSet = new ArrayList <>();
226+ cellSet .add (cell1 );
227+ cellSet .add (cell2 );
228+ cellSet .add (cell3 );
290229
291- HashSet <ChoiceCell > pendingDeleteSet = new HashSet <>();
292- pendingDeleteSet .add (cell1 );
293- pendingDeleteSet .add (cell2 );
294- pendingDeleteSet .add (cell3 );
295-
296- csm .preloadedChoices .clear ();
297- csm .preloadedChoices = pendingDeleteSet ;
298-
299- List <ChoiceCell > choices = new ArrayList <>();
300- choices .add (cell2 );
301-
302- HashSet <ChoiceCell > returnedChoices = csm .choicesToBeDeletedWithArray (choices );
230+ ISdl internalInterface = mock (ISdl .class );
231+ when (internalInterface .getTaskmaster ()).thenReturn (taskmaster );
232+ FileManager fileManager = null ;
233+ ChoiceSetManager newCSM = new ChoiceSetManager (internalInterface , fileManager );
234+ newCSM .preloadChoices (cellSet , new CompletionListener () {
235+ @ Override
236+ public void onComplete (boolean success ) {
303237
304- assertEquals (returnedChoices .size (), 1 );
305- for (ChoiceCell cell : returnedChoices ) {
306- assertEquals (cell .getText (), "test2" );
307- }
238+ }
239+ });
240+ assertEquals (csm .transactionQueue .getTasksAsList ().size (), 0 );
308241 }
309242
310243 @ Test
@@ -474,51 +407,4 @@ public void testDismissingQueuedKeyboard() {
474407 verify (testKeyboardOp , times (0 )).dismissKeyboard ();
475408 verify (testKeyboardOp2 , times (1 )).dismissKeyboard ();
476409 }
477-
478- @ Test
479- public void testUniquenessForAvailableFields () {
480- WindowCapability windowCapability = new WindowCapability ();
481- TextField secondaryText = new TextField ();
482- secondaryText .setName (TextFieldName .secondaryText );
483- TextField tertiaryText = new TextField ();
484- tertiaryText .setName (TextFieldName .tertiaryText );
485-
486- List <TextField > textFields = new ArrayList <>();
487- textFields .add (secondaryText );
488- textFields .add (tertiaryText );
489- windowCapability .setTextFields (textFields );
490-
491- ImageField choiceImage = new ImageField ();
492- choiceImage .setName (ImageFieldName .choiceImage );
493- ImageField choiceSecondaryImage = new ImageField ();
494- choiceSecondaryImage .setName (ImageFieldName .choiceSecondaryImage );
495- List <ImageField > imageFieldList = new ArrayList <>();
496- imageFieldList .add (choiceImage );
497- imageFieldList .add (choiceSecondaryImage );
498- windowCapability .setImageFields (imageFieldList );
499-
500- csm .defaultMainWindowCapability = windowCapability ;
501-
502- ChoiceCell cell1 = new ChoiceCell ("Item 1" , "null" , "tertiaryText" , null , TestValues .GENERAL_ARTWORK , TestValues .GENERAL_ARTWORK );
503- ChoiceCell cell2 = new ChoiceCell ("Item 1" , "null2" , "tertiaryText2" , null , null , null );
504- List <ChoiceCell > choiceCellList = new ArrayList <>();
505- choiceCellList .add (cell1 );
506- choiceCellList .add (cell2 );
507-
508- List <ChoiceCell > removedProperties = csm .removeUnusedProperties (choiceCellList );
509- assertNotNull (removedProperties .get (0 ).getSecondaryText ());
510-
511- textFields .remove (secondaryText );
512- textFields .remove (tertiaryText );
513- imageFieldList .remove (choiceImage );
514- imageFieldList .remove (choiceSecondaryImage );
515-
516- removedProperties = csm .removeUnusedProperties (choiceCellList );
517- csm .addUniqueNamesBasedOnStrippedCells (removedProperties , choiceCellList );
518- assertEquals (choiceCellList .get (1 ).getUniqueText (), "Item 1 (2)" );
519-
520-
521- }
522-
523-
524410}
0 commit comments