Skip to content

Commit 053ac1b

Browse files
committed
Add duplicate name check to setStates()
Add testAssignSameNameStateListToSoftButtonObject() to test the new behavior
1 parent 9a82059 commit 053ac1b

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/SoftButtonManagerTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,26 @@ public void testAssignNonEmptyStateListToSoftButtonObject() {
461461

462462
assertEquals(stateList2, softButtonObject.getStates());
463463
}
464+
465+
/**
466+
* Test assigning a state list with states that have the same name to existing SoftButtonObject
467+
*/
468+
@Test
469+
public void testAssignSameNameStateListToSoftButtonObject() {
470+
List<SoftButtonState> stateListUnique = new ArrayList<>();
471+
SoftButtonState softButtonState1 = new SoftButtonState("hello_there", "Hello there", null);
472+
stateListUnique.add(softButtonState1);
473+
474+
List<SoftButtonState> stateListDuplicateNames = new ArrayList<>();
475+
SoftButtonState softButtonState2 = new SoftButtonState("general_kenobi", "General Kenobi", null);
476+
stateListDuplicateNames.add(softButtonState2);
477+
SoftButtonState softButtonState3 = new SoftButtonState("general_kenobi", "General Kenobi Again", null);
478+
stateListDuplicateNames.add(softButtonState3);
479+
480+
SoftButtonObject softButtonObject = new SoftButtonObject("general_kenobi", stateListUnique, "general_kenobi", null);
481+
482+
softButtonObject.setStates(stateListDuplicateNames);
483+
484+
assertEquals(stateListUnique, softButtonObject.getStates());
485+
}
464486
}

base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ public void setStates(@NonNull List<SoftButtonState> states) {
272272
DebugTool.logError(TAG,"The state list is empty");
273273
return;
274274
}
275+
// Make sure there aren't two states with the same name
276+
if (hasTwoStatesOfSameName(states)) {
277+
DebugTool.logError(TAG, "Two states have the same name in states list for soft button object");
278+
return;
279+
}
275280

276281
this.states = states;
277282
}

0 commit comments

Comments
 (0)