diff --git a/src/main/java/Application/MenuManager.java b/src/main/java/Application/MenuManager.java index 539ed66..62944b1 100644 --- a/src/main/java/Application/MenuManager.java +++ b/src/main/java/Application/MenuManager.java @@ -16,6 +16,12 @@ public class MenuManager { menuList.add(menu); } + public int getSize() { + if(inRootMenu()) + return menuList.size(); + return currentMenu.getSubMenuList().size(); + } + public void select(int i) { if (currentMenu == null) this.currentMenu = menuList.get(i); @@ -41,10 +47,10 @@ public class MenuManager { public String getFormattedMenuList() { StringBuilder result = new StringBuilder(); ArrayList baseMenuList = this.menuList; - if(!inRootMenu()) + if (!inRootMenu()) baseMenuList = currentMenu.getSubMenuList(); - for(int i = 0; i < baseMenuList.size(); i++) + for (int i = 0; i < baseMenuList.size(); i++) result.append(i + 1).append(": ").append(baseMenuList.get(i).getName()).append("\n"); return result.toString(); diff --git a/src/test/java/Application/MenuManagerTest.java b/src/test/java/Application/MenuManagerTest.java index 45e7b65..111bf13 100644 --- a/src/test/java/Application/MenuManagerTest.java +++ b/src/test/java/Application/MenuManagerTest.java @@ -73,4 +73,13 @@ class MenuManagerTest { mm.select(0); assertEquals(mm.getFormattedMenuList(), "1: Menu1.1\n"); } + + @Test + void getSize() { + assertEquals(mm.getSize(), 2); + mm.select(0); + assertEquals(mm.getSize(), 1); + mm.select(0); + assertEquals(mm.getSize(), 0); + } } \ No newline at end of file