diff options
author | Noah Stanford <noah@livio.io> | 2021-12-15 17:15:10 -0500 |
---|---|---|
committer | Noah Stanford <noah@livio.io> | 2021-12-15 17:15:10 -0500 |
commit | 8413d94758ed86ba951e2c97cca30ffd2101a4a8 (patch) | |
tree | cd626b09fde7ed2af87d8d31f0df017067163151 | |
parent | b00cea51e090fb572fbeac33ad9a38a0bec96411 (diff) | |
download | sdl_android-8413d94758ed86ba951e2c97cca30ffd2101a4a8.tar.gz |
Make changes discussed in #1776 review
Remove attemptedToAssignEmptyStateList and getAttemptedToAssignEmptyStateList() from SoftButtonObject
Change unit tests to reflect the removals stated above
Add testConstructingSoftButtonObjectWithNonEmptyStateList() and testAssignNonEmptyStateListToSoftButtonObject() to test normal functionality
2 files changed, 40 insertions, 20 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/SoftButtonManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/SoftButtonManagerTests.java index 67f50e3a2..b0939f424 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/SoftButtonManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/SoftButtonManagerTests.java @@ -33,6 +33,7 @@ import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.test.Validator; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -57,6 +58,8 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import android.database.sqlite.SQLiteCantOpenDatabaseException; + /** * This is a unit test class for the SmartDeviceLink library manager class : * {@link SoftButtonManager} @@ -411,12 +414,20 @@ public class SoftButtonManagerTests { @Test public void testConstructSoftButtonObjectWithEmptyStateList() { List<SoftButtonState> stateList = new ArrayList<>(); - // Uncommenting the following lines should make the test fail - // SoftButtonState softButtonState = new SoftButtonState("object1-state1", "o1s1", null); - // stateList.add(softButtonState); - SoftButtonObject softButtonObject = new SoftButtonObject("hi", stateList, "Hi", null); + SoftButtonObject softButtonObject1 = new SoftButtonObject("hello_there", stateList, "general_kenobi", null); + assertNull(softButtonObject1.getStates()); + } - assertTrue(softButtonObject.getAttemptedToAssignEmptyStateList()); + /** + * Test constructing SoftButtonObject with an empty state list + */ + @Test + public void testConstructingSoftButtonObjectWithNonEmptyStateList() { + List<SoftButtonState> stateList = new ArrayList<>(); + SoftButtonState softButtonState = new SoftButtonState("general_kenobi", "General Kenobi", null); + stateList.add(softButtonState); + SoftButtonObject softButtonObject2 = new SoftButtonObject("hello_there_again", stateList, "general_kenobi", null); + assertEquals(stateList, softButtonObject2.getStates()); } /** @@ -428,8 +439,23 @@ public class SoftButtonManagerTests { SoftButtonState softButtonState = new SoftButtonState("object1-state1", "o1s1", null); SoftButtonObject softButtonObject = new SoftButtonObject("hi", softButtonState, null); - // Commenting the following line should make the test fail + + softButtonObject.setStates(stateList); + assertNotEquals(stateList, softButtonObject.getStates()); + } + + /** + * Test assigning a nonempty state list to existing SoftButtonObject + */ + @Test + public void testAssignNonEmptyStateListToSoftButtonObject() { + List<SoftButtonState> stateList = new ArrayList<>(); + SoftButtonState softButtonState = new SoftButtonState("object1-state1", "o1s1", null); + + SoftButtonObject softButtonObject = new SoftButtonObject("hi", softButtonState, null); + + stateList.add(softButtonState); softButtonObject.setStates(stateList); - assertTrue(softButtonObject.getAttemptedToAssignEmptyStateList()); + assertEquals(stateList, softButtonObject.getStates()); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java b/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java index a17bac86b..394e253f4 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java @@ -61,7 +61,6 @@ public class SoftButtonObject implements Cloneable{ private int buttonId; private OnEventListener onEventListener; private UpdateListener updateListener; - private boolean attemptedToAssignEmptyStateList = false; /** * Create a new instance of the SoftButtonObject with multiple states @@ -74,8 +73,11 @@ public class SoftButtonObject implements Cloneable{ */ public SoftButtonObject(@NonNull String name, @NonNull List<SoftButtonState> states, @NonNull String initialStateName, OnEventListener onEventListener) { - setStates(states); - + // If the list of states is empty, throw an error with DebugTool and return + if (states.isEmpty()) { + DebugTool.logError(TAG,"The state list is empty"); + return; + } // Make sure there aren't two states with the same name if (hasTwoStatesOfSameName(states)) { DebugTool.logError(TAG, "Two states have the same name in states list for soft button object"); @@ -86,6 +88,7 @@ public class SoftButtonObject implements Cloneable{ this.currentStateName = initialStateName; this.buttonId = SOFT_BUTTON_ID_NOT_SET_VALUE; this.onEventListener = onEventListener; + this.states = states; } /** @@ -267,8 +270,7 @@ public class SoftButtonObject implements Cloneable{ */ public void setStates(@NonNull List<SoftButtonState> states) { // If the list of states is empty, throw an error with DebugTool and return - attemptedToAssignEmptyStateList = states.isEmpty(); - if (attemptedToAssignEmptyStateList) { + if (states.isEmpty()) { DebugTool.logError(TAG,"The state list is empty"); return; } @@ -405,12 +407,4 @@ public class SoftButtonObject implements Cloneable{ return null; } - /** - * Used to make unit testing easier by removing the need to read debug logs programmatically - * - * @return True if the last list passed to setStates() was empty and false otherwise - */ - public boolean getAttemptedToAssignEmptyStateList() { - return attemptedToAssignEmptyStateList; - } } |