Browse Source

Added getFormattedMenuList method to MenuManager with test for printing to Console

feature-menu
Nick Stolbov 3 years ago
parent
commit
691ca536ea
  1. 12
      src/main/java/Application/MenuManager.java
  2. 7
      src/test/java/Application/MenuManagerTest.java

12
src/main/java/Application/MenuManager.java

@ -38,4 +38,16 @@ public class MenuManager {
return this.currentMenu == null;
}
public String getFormattedMenuList() {
StringBuilder result = new StringBuilder();
ArrayList<Menu> baseMenuList = this.menuList;
if(!inRootMenu())
baseMenuList = currentMenu.getSubMenuList();
for(int i = 0; i < baseMenuList.size(); i++)
result.append(i + 1).append(": ").append(baseMenuList.get(i).getName()).append("\n");
return result.toString();
}
}

7
src/test/java/Application/MenuManagerTest.java

@ -66,4 +66,11 @@ class MenuManagerTest {
Assertions.fail("Test failed: " + e.getMessage());
}
}
@Test
void getFormattedMenuList(){
assertEquals(mm.getFormattedMenuList(), "1: Menu1\n2: Menu2\n");
mm.select(0);
assertEquals(mm.getFormattedMenuList(), "1: Menu1.1\n");
}
}
Loading…
Cancel
Save