Skip to content

Commit b890c4e

Browse files
HeniganHenigan
authored andcommitted
Merge branch 'develop' into bugfix/issue_1720
2 parents 0c711c8 + 470e703 commit b890c4e

37 files changed

Lines changed: 2693 additions & 1739 deletions

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCellTests.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void testSettersAndGetters() {
6161
choiceCell.setVoiceCommands(TestValues.GENERAL_STRING_LIST);
6262
choiceCell.setArtwork(artwork);
6363
choiceCell.setSecondaryArtwork(artwork);
64-
choiceCell.setUniqueText(TestValues.GENERAL_STRING);
64+
choiceCell.setUniqueTextId(TestValues.GENERAL_INT);
6565

6666
// use getters and assert equality
6767
assertEquals(choiceCell.getText(), TestValues.GENERAL_STRING);
@@ -71,7 +71,7 @@ public void testSettersAndGetters() {
7171
assertEquals(choiceCell.getArtwork(), artwork);
7272
assertEquals(choiceCell.getSecondaryArtwork(), artwork);
7373
assertEquals(choiceCell.getChoiceId(), MAX_ID);
74-
assertEquals(choiceCell.getUniqueText(), TestValues.GENERAL_STRING);
74+
assertEquals(choiceCell.getUniqueTextId(), TestValues.GENERAL_INTEGER);
7575
}
7676

7777
@Test
@@ -121,14 +121,27 @@ public void testCellEquality() {
121121
choiceCell3.setSecondaryText(TestValues.GENERAL_STRING);
122122
choiceCell3.setTertiaryText(TestValues.GENERAL_STRING);
123123

124-
//UniqueText should not be taken into consideration when checking equality
125-
choiceCell.setUniqueText(TestValues.GENERAL_STRING);
126-
choiceCell2.setUniqueText(TestValues.GENERAL_STRING);
127-
choiceCell3.setUniqueText(TestValues.GENERAL_STRING);
128-
129124
// Make sure our overridden method works, even though these are different objects in memory
130125
assertTrue(choiceCell.equals(choiceCell2));
131126
assertFalse(choiceCell.equals(choiceCell3));
132127

133128
}
129+
130+
@Test
131+
public void testGetUniqueCellText() {
132+
ChoiceCell choiceCell = new ChoiceCell("Test");
133+
ChoiceCell choiceCell2 = new ChoiceCell("Test");
134+
choiceCell2.setUniqueTextId(2);
135+
ChoiceCell choiceCell3 = new ChoiceCell("Test");
136+
choiceCell3.setUniqueTextId(3);
137+
138+
assertEquals((int) choiceCell.getUniqueTextId(), 1);
139+
assertEquals(choiceCell.getUniqueText(), "Test");
140+
141+
assertEquals((int) choiceCell2.getUniqueTextId(), 2);
142+
assertEquals(choiceCell2.getUniqueText(), "Test (2)");
143+
144+
assertEquals((int) choiceCell3.getUniqueTextId(), 3);
145+
assertEquals(choiceCell3.getUniqueText(), "Test (3)");
146+
}
134147
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetManagerTests.java

Lines changed: 32 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,21 @@
3838

3939
import com.livio.taskmaster.Taskmaster;
4040
import com.smartdevicelink.managers.BaseSubManager;
41+
import com.smartdevicelink.managers.CompletionListener;
4142
import com.smartdevicelink.managers.ISdl;
4243
import com.smartdevicelink.managers.file.FileManager;
43-
import com.smartdevicelink.proxy.rpc.ImageField;
4444
import com.smartdevicelink.proxy.rpc.KeyboardCapabilities;
4545
import com.smartdevicelink.proxy.rpc.KeyboardLayoutCapability;
4646
import com.smartdevicelink.proxy.rpc.KeyboardProperties;
4747
import com.smartdevicelink.proxy.rpc.SdlMsgVersion;
48-
import com.smartdevicelink.proxy.rpc.TextField;
4948
import com.smartdevicelink.proxy.rpc.WindowCapability;
5049
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
51-
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
5250
import com.smartdevicelink.proxy.rpc.enums.KeyboardInputMask;
5351
import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout;
5452
import com.smartdevicelink.proxy.rpc.enums.KeypressMode;
5553
import com.smartdevicelink.proxy.rpc.enums.Language;
5654
import com.smartdevicelink.proxy.rpc.enums.SystemContext;
57-
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
5855
import com.smartdevicelink.proxy.rpc.enums.TriggerSource;
59-
import com.smartdevicelink.test.TestValues;
6056

6157
import org.junit.After;
6258
import org.junit.Before;
@@ -68,13 +64,10 @@
6864
import java.util.Arrays;
6965
import java.util.Collections;
7066
import java.util.HashSet;
71-
import java.util.LinkedHashSet;
72-
import java.util.List;
7367

7468
import static junit.framework.TestCase.assertEquals;
7569
import static junit.framework.TestCase.assertFalse;
7670
import static junit.framework.TestCase.assertNotNull;
77-
import static junit.framework.TestCase.assertNotSame;
7871
import static junit.framework.TestCase.assertNull;
7972
import static junit.framework.TestCase.assertTrue;
8073
import 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
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/DeleteChoicesOperationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void setUp() throws Exception {
6666
cellsToDelete.add(cell2);
6767

6868
ISdl internalInterface = mock(ISdl.class);
69-
deleteChoicesOperation = new DeleteChoicesOperation(internalInterface, cellsToDelete, null);
69+
deleteChoicesOperation = new DeleteChoicesOperation(internalInterface, cellsToDelete, null, null);
7070
}
7171

7272

0 commit comments

Comments
 (0)