Skip to content

Commit

Permalink
Merge pull request #1610 from smartdevicelink/feature/issue_1605_menu…
Browse files Browse the repository at this point in the history
…_manager_refactor

Refactor MenuManager to use queues
  • Loading branch information
bilal-alsharifi authored Sep 23, 2021
2 parents 9a2398f + 7088a04 commit 6834f99
Show file tree
Hide file tree
Showing 22 changed files with 3,031 additions and 2,054 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public void testClone() {
}

public static boolean equalTest(SdlArtwork original, SdlArtwork clone) {
if (original == null && clone == null) {
return true;
}

assertNotNull(original);
assertNotNull(clone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ public void testInstantiation() {
assertNull(screenManager.getTextField2Type());
assertNull(screenManager.getTextField3Type());
assertNull(screenManager.getTextField4Type());
assertNull(screenManager.getMenu());
assertTrue(screenManager.getMenu().isEmpty());
assertNull(screenManager.getVoiceCommands());
assertTrue(screenManager.getSoftButtonObjects().isEmpty());
assertNull(screenManager.getSoftButtonObjectByName("test"));
assertNull(screenManager.getSoftButtonObjectById(1));
assertEquals(screenManager.getDynamicMenuUpdatesMode(), DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE);
assertEquals(screenManager.getState(), BaseSubManager.READY);
assertNull(screenManager.getMenuConfiguration());
assertNull(screenManager.getMenuConfiguration().getMenuLayout());
assertNull(screenManager.getMenuConfiguration().getSubMenuLayout());
}

@Test
Expand Down Expand Up @@ -147,10 +148,9 @@ public void testSetMenuManagerFields() {
screenManager.setMenu(TestValues.GENERAL_MENUCELL_LIST);
screenManager.setMenuConfiguration(TestValues.GENERAL_MENU_CONFIGURATION);

assertEquals(screenManager.getMenu(), TestValues.GENERAL_MENUCELL_LIST);
assertEquals(screenManager.getDynamicMenuUpdatesMode(), DynamicMenuUpdatesMode.FORCE_ON);
// Should not set because of improper RAI response and improper HMI states
assertNull(screenManager.getMenuConfiguration());
assertEquals(screenManager.getMenu(), TestValues.GENERAL_MENUCELL_LIST);
assertEquals(screenManager.getMenuConfiguration(), TestValues.GENERAL_MENU_CONFIGURATION);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,29 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Arrays;
import java.util.List;

import static com.smartdevicelink.managers.screen.menu.DynamicMenuUpdateAlgorithm.MenuCellState.ADD;
import static com.smartdevicelink.managers.screen.menu.DynamicMenuUpdateAlgorithm.MenuCellState.DELETE;
import static com.smartdevicelink.managers.screen.menu.DynamicMenuUpdateAlgorithm.MenuCellState.KEEP;
import static junit.framework.TestCase.assertEquals;

@RunWith(AndroidJUnit4.class)
public class RunScoreTests {
public class DynamicMenuUpdateRunScoreTests {

@Test
public void testSettersAndGetters() {

// set everything - we only use the constructor to set variables in the Menu Manager
RunScore runScore = new RunScore(TestValues.GENERAL_INT, TestValues.GENERAL_INTEGER_LIST, TestValues.GENERAL_INTEGER_LIST);
List<DynamicMenuUpdateAlgorithm.MenuCellState> oldStatus = Arrays.asList(KEEP, DELETE);
List<DynamicMenuUpdateAlgorithm.MenuCellState> updatedStatus = Arrays.asList(KEEP, ADD);
DynamicMenuUpdateRunScore runScore = new DynamicMenuUpdateRunScore(oldStatus, updatedStatus, TestValues.GENERAL_INT);

// use getters and assert equality
assertEquals(runScore.getScore(), TestValues.GENERAL_INT);
assertEquals(runScore.getCurrentMenu(), TestValues.GENERAL_INTEGER_LIST);
assertEquals(runScore.getOldMenu(), TestValues.GENERAL_INTEGER_LIST);
assertEquals(runScore.getOldStatus(), oldStatus);
assertEquals(runScore.getUpdatedStatus(), updatedStatus);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNotSame;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertNotEquals;

@RunWith(AndroidJUnit4.class)
public class MenuCellTests {
Expand All @@ -63,7 +63,6 @@ public void onTriggered(TriggerSource trigger) {

@Test
public void testSettersAndGetters() {

// set everything
MenuCell menuCell = new MenuCell(TestValues.GENERAL_STRING, null, null, menuSelectionListener);
menuCell.setIcon(TestValues.GENERAL_ARTWORK);
Expand Down Expand Up @@ -91,28 +90,23 @@ public void testSettersAndGetters() {

@Test
public void testConstructors() {

// first constructor was tested in previous method, use the last two here

MenuCell menuCell3 = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_STRING_LIST, menuSelectionListener);
assertEquals(menuCell3.getTitle(), TestValues.GENERAL_STRING);
assertEquals(menuCell3.getIcon(), TestValues.GENERAL_ARTWORK);
assertEquals(menuCell3.getVoiceCommands(), TestValues.GENERAL_STRING_LIST);
assertEquals(menuCell3.getMenuSelectionListener(), menuSelectionListener);
assertEquals(menuCell3.getUniqueTitle(), TestValues.GENERAL_STRING);

MenuCell menuCell4 = new MenuCell(TestValues.GENERAL_STRING, null, null, menuSelectionListener);
assertEquals(menuCell4.getTitle(), TestValues.GENERAL_STRING);
assertEquals(menuCell4.getMenuSelectionListener(), menuSelectionListener);
assertEquals(menuCell4.getUniqueTitle(), TestValues.GENERAL_STRING);

MenuCell menuCell5 = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_MENU_LAYOUT, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_MENUCELL_LIST);
assertEquals(menuCell5.getTitle(), TestValues.GENERAL_STRING);
assertEquals(menuCell5.getIcon(), TestValues.GENERAL_ARTWORK);
assertEquals(menuCell5.getSubMenuLayout(), TestValues.GENERAL_MENU_LAYOUT);
assertEquals(menuCell5.getSubCells(), TestValues.GENERAL_MENUCELL_LIST);
assertEquals(menuCell5.getUniqueTitle(), TestValues.GENERAL_STRING);


MenuCell menuCell6 = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_STRING, TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_STRING_LIST, menuSelectionListener);
assertEquals(menuCell6.getTitle(), TestValues.GENERAL_STRING);
Expand All @@ -139,36 +133,34 @@ public void testConstructors() {

@Test
public void testEquality() {
MenuCell menuCell1 = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_STRING_LIST, menuSelectionListener);
MenuCell menuCell1_1 = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_STRING_LIST, menuSelectionListener);
menuCell1.setSubCells(Collections.singletonList(menuCell1_1));

//We should use assertTrue (or assertFalse) because we want to use the overridden equals() method

MenuCell menuCell = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_STRING_LIST, menuSelectionListener);
menuCell.setSecondaryText(TestValues.GENERAL_STRING);
menuCell.setTertiaryText(TestValues.GENERAL_STRING);
menuCell.setSecondaryArtwork(TestValues.GENERAL_ARTWORK);
MenuCell menuCell2 = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_STRING_LIST, menuSelectionListener);
menuCell2.setSecondaryText(TestValues.GENERAL_STRING);
menuCell2.setTertiaryText(TestValues.GENERAL_STRING);
menuCell2.setSecondaryArtwork(TestValues.GENERAL_ARTWORK);
MenuCell menuCell2_1 = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_STRING_LIST, menuSelectionListener);
menuCell2.setSubCells(Collections.singletonList(menuCell2_1));

// these are the same object, should be equal.
assertTrue(menuCell.equals(menuCell));
assertEquals(menuCell1, menuCell1);

// Make sure these are marked as equals, even though they are different objects
assertTrue(menuCell.equals(menuCell2));
assertEquals(menuCell1, menuCell2);

MenuCell menuCell3 = new MenuCell(TestValues.GENERAL_STRING, null, TestValues.GENERAL_STRING_LIST, menuSelectionListener);

// these should be different
assertFalse(menuCell.equals(menuCell3));
assertNotEquals(menuCell1, menuCell3);

menuCell1_1.setTitle("new title");

// Make sure sub cells are not compared
assertEquals(menuCell1, menuCell2);
}

@Test
public void testClone() {
MenuCell original = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_STRING_LIST, menuSelectionListener);
original.setSecondaryText(TestValues.GENERAL_STRING);
original.setTertiaryText(TestValues.GENERAL_STRING);
original.setSecondaryArtwork(TestValues.GENERAL_ARTWORK);
MenuCell clone = original.clone();

assertNotNull(clone);
Expand Down Expand Up @@ -208,8 +200,5 @@ public void testClone() {

assertNotSame(originalSubCells.get(i), cloneSubCells.get(i));
}


}

}
Loading

0 comments on commit 6834f99

Please sign in to comment.